Question

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.

Was it helpful?

Solution

EDIT:The question changed.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top