0
np.where(A ==2)[0]

gives the indexes of A where elements are equal to 2.

How do you generalize to a list of possible values?

I am looking for something like:

np.where(A in ([2,3,6,8]))[0]
3

1 Answer 1

1

Since NumPy 1.13 you can use the isin function.

In prior versions there was in1d.

Test:

A = np.array([1, 2, 3, 4, 5])
print(np.isin(A, [2, 3, 6, 8]))

Results:

[False  True  True False False]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.