问题
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.
回答1:
EDIT:The question changed.
You just want to evaluate np.where(v1==v2)[0]
来源:https://stackoverflow.com/questions/22605554/elementwise-logical-comparison-of-numpy-arrays