Numpy:如何获得 2 个矩阵的不同项?

Numpy: how to get the items that are different of 2 matrices?

我知道如何使用 Numpy 比较 2 个整数矩阵。但是 Numpy 是否提供了一种方法来获取它们之间不同的元素列表?

是这样的吗?

>>> import numpy as np
>>> a = np.zeros(3)
>>> b = np.zeros(3)
>>> a[1] = 1
>>> a == b
array([ True, False,  True], dtype=bool)

对于花车:http://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.isclose.html

>>> np.isclose(a,b)
array([ True, False,  True], dtype=bool)

不同元素的索引

 >>>[i for i,val in enumerate(np.isclose(a,b)) if val == False]

(改用 numpy)

>>> np.where(np.isclose(a,b) == False)

查找不同元素的值:

 >>> d = [i for i,val in enumerate(np.isclose(a,b)) if val == False]
 >>> a[d]
 array([ 1.])
 >>> b[d]
 array([ 0.])