0

I have two arrays full of ID's of objects and I only want to keep the ID's of the objects the exist in both arrays. Example:

a = np.array([1, 2, 3, 2, 4, 1])
b = np.array([3, 4, 5, 6])

So ideal output from this would be an array that has searched through arrays a and b and gives me an array of only the objects that are present in both lists. Something similar to:

c = np.array([3, 4])

This array shows that the ID 3 and the ID 4 are present in both lists. Is there any way to do this?

KGreen
  • 123
  • 5
  • 9

1 Answers1

2

Don't use arrays, since you want sets:

set(a) & set(b)

If you need the result in an array:

np.array(list(set(a) & set(b)))
kabanus
  • 24,623
  • 6
  • 41
  • 74