I have two numpy arrays and I'd like to get the indices of all elements in the first array that are in the second array. For example:
import numpy as np
x = np.array([0,1,1,2,3,4,5,5])
y = np.array([1,3])
# want to get np.array([1,2,4])
If y were a scalar, I could just do np.where(x == y). Is there an equivalent for arrays of values?
You can numpy.where with numpy.in1d:
>>> np.where(np.in1d(x, y))
(array([1, 2, 4]),)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With