1

I want to find indexes of array like x = np.array([[1, 1, 1], [2, 2, 2]]) where elements equals to y = np.array([1, 1, 1]). So I did this:

In: np.where(x == y)
Out: (array([0, 0, 0]), array([0, 1, 2]))

It is the correct answer. But I expect to get only index 0 because the zero element of x is equal to y.

Kenenbek Arzymatov
  • 8,439
  • 19
  • 58
  • 109

1 Answers1

3

You need to use (x == y).all(axis=1) to reduce the comparison result over axis=1 first, i.e all elements are equal:

np.where((x == y).all(axis=1))[0]
# array([0])
Psidom
  • 209,562
  • 33
  • 339
  • 356