0

I have a numpy array A, of say length 100, and another array B, of length 4.

I want to get a mask of also length 100, and this mask will have values of TRUE, when the element of A equals ANY of the elements of B, and FALSE otherwise. How can I do that in an efficient way?

0

1 Answer 1

0

Try:

a = np.random.rand(100)
b = np.random.rand(4)
print([(element in b) for element in a])
print('\n')
print([(element in a) for element in b])

I think that's what you want

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, although I would rather do it without a for-loop. Apparently this works `np.in1d'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.