[英]Elementwise logical comparison of numpy arrays
I have two numpy arrays of the same shape. 我有两个相同形状的Numpy数组。 The elements in the arrays are random integers from [0,N]. 数组中的元素是[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. 我可以编写一个循环遍历所有元素的循环,但是我假设可以更快地实现所需的输出。
EDIT:The question changed. 编辑:问题改变了。
You just want to evaluate np.where(v1==v2)[0]
您只想评估np.where(v1==v2)[0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.