Well, that’s what I came up with.
To find the value of a single multidimensional index, say ii = np.array([1,2]) , we can do:
n.where((A == ii).all(axis=1))[0]
Let it break, we have A == ii , which will give elementary comparisons with ii for each row of A We want the whole line to be true, so we add .all(axis=1) to collapse them. To find where these indexes occur, we connect it to np.where and get the first value of the tuple.
Now I have no quick way to do this with multiple indexes (although I have a feeling that there is one). However, this will do its job:
np.hstack([np.where((A == values[i]).all(axis=1))[0] for i in xrange(len(values))])
It simply calls above, for each value, values and combines the result.
Update:
Here is for the multidimensional case (all in one move, should be pretty fast):
np.where((np.expand_dims(A, -1) == values.T).all(axis=1).any(axis=1))[0]
source share