[NumPy-Tickets] [NumPy] #1980: Matrix A from zeros, after changing values, yields strange A*A.T behavior
NumPy Trac
numpy-tickets@scipy....
Mon Nov 14 21:38:10 CST 2011
#1980: Matrix A from zeros, after changing values, yields strange A*A.T behavior
----------------------+-----------------------------------------------------
Reporter: ehassler | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: Unscheduled
Component: Other | Version: 1.6.0
Keywords: |
----------------------+-----------------------------------------------------
Apologies if this is expected behavior, or if dupe. I searched trac for
"zeros" and "multiply" and found nothing that described this.
I'm making a permutation matrix P, starting with zeros and setting the
1's. When I do P.T*P or P*P.T I get all 0's back. But if I multiply P by
an identical matrix manually constructed, or if I use asmatrix to redefine
P as itself, I get the expected behavior (that is, I get an identity
matrix back). I've included example code at the bottom.
It seems like either one of the following should happen:
- P should zero out everything it's multiplied into and raise errors when
I change a value, forcing it to be all zeros all the time.
- P*P.T = I
import numpy;
P0 = numpy.zeros((6,6),dtype=numpy.float64);
for coord in zip(range(6),(1,3,5,0,2,4)):
P0[coord[0],coord[1]] = 1.;
P1 = numpy.matrix([
[ 0., 1., 0., 0., 0., 0.],
[ 0., 0., 0., 1., 0., 0.],
[ 0., 0., 0., 0., 0., 1.],
[ 1., 0., 0., 0., 0., 0.],
[ 0., 0., 1., 0., 0., 0.],
[ 0., 0., 0., 0., 1., 0.]
], dtype=numpy.float64);
print numpy.all(P0 == P1); # True
print numpy.all(P0*P0.T == P1*P1.T) # False
print numpy.all(P0*P1.T == P1*P1.T) # True
print numpy.all(P1*P0.T == P1*P1.T) # True
P0 = numpy.asmatrix(P0,dtype=numpy.float64);
print numpy.all(P0*P0.T == P1*P1.T) # True
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1980>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list