I am looking for a way to find indices of an array of queries in a multidimensional array. For example:
arr = np.array([[17, 5, 19, 9],
[18, 13, 3, 7],
[ 8, 1, 4, 2],
[ 8, 9, 7, 19],
[ 6, 11, 8, 5],
[11, 16, 13, 18],
[ 0, 1, 2, 9],
[ 1, 7, 4, 6]])
I can find indices for one query:
np.where(arr==1)
# (array([2, 6, 7]), array([1, 1, 0]))
Is there any numpy solution to do this for multiple values replacing the following for loop?
for q in queries:
np.where(arr==q)
If both the array and queries were one-dimensional, I could use searchsorted as this answer but it doesn't work for multidimensional arrays.