I'm trying to figure out what is going on here, but I'm a little bit baffled. I am getting unexpected results working with a transposed NumPy identity matrix (which should have no effect). For example:
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
Outputs:
A == At: True
A == Ad: False
This is incorrect since the 2nd statement should be true. Now if we do this instead:
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
Outputs:
B == Bt: True
B == Bd: True
This is the desired result. The only difference is the addition of the copy operation in the 2nd case. Another funny thing is that if I set N to a smaller number (say 100 instead of 1000), the answers are correct in both cases.
What is going on?
(Edit: I am running Numpy version '1.11.1', on OS X 10.10.5 with Python 2.7.10 and IPython 4.0.0)