1

I have two numpy arrays of the same shape. The elements in the arrays are random integers from [0,N]. I need to check which (if any) of the elements in the same position in the arrays are equal.

The output I need are the positions of the same elements.

mock code:

A=np.array([0,1])
B=np.array([1,0])
C=np.array([1,1])
np.any_elemenwise(A,B)
np.any_elemenwise(A,C)
np.any_elemenwise(A,A)

desired output:

[]
[1]
[0,1]

I can write a loop going through all of the elements one by one, but I assume that the desired output can be achieved much faster.

Amro
  • 123,847
  • 25
  • 243
  • 454
Artturi Björk
  • 3,643
  • 6
  • 27
  • 35

1 Answers1

6

EDIT:The question changed.

You just want to evaluate np.where(v1==v2)[0]

gg349
  • 21,996
  • 5
  • 54
  • 64