I have an array of integers and want to find where that array is equal to any value in a list of multiple values.
This can easily be done by treating each value indi
As of NumPy v0.13, you can use np.isin, which works on multi-dimensional arrays:
>>> element = 2*np.arange(4).reshape((2, 2))
>>> element
array([[0, 2],
[4, 6]])
>>> test_elements = [1, 2, 4, 8]
>>> mask = np.isin(element, test_elements)
>>> mask
array([[ False, True],
[ True, False]])
The accepted answer with np.in1d
works only with 1d arrays and requires reshaping for the desired result. This is good for versions of NumPy before v0.13.