4

I have an array 'A' of shape(50,3) and another array 'B' of shape (1,3).

Actually this B is a row in A. So I need to find its row location.

I used np.where(A==B), but it gives the locations searched element wise. For example, below is the result i got :

>>> np.where(A == B)
(array([ 3,  3,  3, 30, 37, 44]), array([0, 1, 2, 1, 2, 0]))

Actually B is the 4th row in A (in my case). But above result gives (3,0)(3,1)(3,2) and others, which are matched element-wise.

Instead of this, i need an answer '3' which is the answer obtained when B searched in A as a whole and it also removes others like (30,1)(37,2)... which are partial matches.

How can i do this in Numpy?

Thank you.

Abid Rahman K
  • 51,886
  • 31
  • 146
  • 157

1 Answers1

12

You can specify the axis:

numpy.where((A == B).all(axis=1))
Benjamin
  • 11,560
  • 13
  • 70
  • 119