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.

1 Answer 1

13

You can specify the axis:

numpy.where((A == B).all(axis=1))
Sign up to request clarification or add additional context in comments.

1 Comment

note that it is a parameter of numpy.all(), not numpy.where().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.