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]
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]
Since NumPy 1.13 you can use the isin
function.
In prior versions there was in1d
.
A = np.array([1, 2, 3, 4, 5])
print(np.isin(A, [2, 3, 6, 8]))
[False True True False False]