Python NumPy转置错误

Python NumPy转置错误,python,numpy,matrix,linear-algebra,transpose,Python,Numpy,Matrix,Linear Algebra,Transpose,我试图弄清楚这里发生了什么,但我有点困惑。我在使用转置的NumPy身份矩阵时得到了意想不到的结果(这应该没有效果)。例如: import numpy as np N = 1000 # case 1: A = np.eye(N) # the identity matrix At = A.T # it's transpose print 'A == At: {}'.format(np.all(A==At)) # should be true Ad = At.dot(A) # identity *

我试图弄清楚这里发生了什么,但我有点困惑。我在使用转置的NumPy身份矩阵时得到了意想不到的结果(这应该没有效果)。例如:

import numpy as np

N = 1000

# case 1:
A = np.eye(N) # the identity matrix
At = A.T # it's transpose
print 'A == At: {}'.format(np.all(A==At)) # should be true
Ad = At.dot(A) # identity * identity = identity
print 'A == Ad: {}'.format(np.all(A==Ad)) # should also be true
产出:

A == At: True
A == Ad: False
B == Bt: True
B == Bd: True
这是不正确的,因为第2条语句应该是正确的。现在,如果我们这样做:

import numpy as np

N = 1000

# case 2:
B = np.eye(N) # the identity matrix
Bt = np.copy(B.T) # it's transpose <==== added copy here
print 'B == Bt: {}'.format(np.all(B==Bt)) # should be true
Bd = Bt.dot(B) # identity * identity = identity
print 'B == Bd: {}'.format(np.all(B==Bd)) # should also be true
这是期望的结果。唯一的区别是在第二种情况下增加了复制操作。另一件有趣的事是,如果我将N设置为一个较小的数字(比如说100而不是1000),那么这两种情况下的答案都是正确的

发生了什么事


(编辑:我正在使用Python 2.7.10和IPython 4.0.0在OS X 10.10.5上运行Numpy版本“1.11.1”)

我刚刚运行了您的代码,并获得了两种情况下的
True
。可能是机器或numpy版本相关?很好@alexblae,我用我的numpy版本和机器信息编辑了我的问题。@frankchannel我猜这是numpy中的一个错误。你知道第一个错误/错误值出现在哪里吗?例如,
np.argwhere(A!=Ad)[0]
我使用的是相同版本的numpy,但在Linux机器上使用的是Python 2.7.6。A.T是否可能正在更改数组的
dtype
。你能打印出
A,At,Ad
的数据类型吗?