I have the following array. I want to extract indices by a search key of array.
np.array([[1,2],[2,2], [3,2], [2,2]])
's shep is (4, 2)
. So the result of searching [2, 2]
should return [1, 3]
which is an index of [2, 2]
. np.argwhere
is a strong function, though, how to use this for my purpose?
In [31]: d=np.array([[1,2],[2,2], [3,2], [2,2]])
In [32]: d
Out[32]:
array([[1, 2],
[2, 2],
[3, 2],
[2, 2]])
In [33]: np.where(d==np.array([2,2]))
Out[33]: (array([0, 1, 1, 2, 3, 3]), array([1, 0, 1, 1, 0, 1]))
In [34]: np.argwhere(d==np.array([2,2]))
Out[34]:
array([[0, 1],
[1, 0],
[1, 1],
[2, 1],
[3, 0],
[3, 1]])