的elementwise numpy的阵列逻辑比较 [英] Elementwise logical comparison of numpy arrays
本文介绍了的elementwise numpy的阵列逻辑比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我具有相同形状的两个numpy的阵列。在阵列中的元件是从[0,N]的随机整数。我需要检查在同一位置的元素的数组它(如果有的话)是相等的。
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.
模拟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)
所需的输出:
[]
[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.
推荐答案
编辑:这个问题改变了
您只是想试用 np.where(V1 V2 = =)[0]
这篇关于的elementwise numpy的阵列逻辑比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文