[Numpy-discussion] an array become a matrix after an element assignment
Forrest Sheng Bao
forrest.bao at gmail.com
Sat Apr 16 23:39:06 EDT 2011
hi,
I encountered a very weird problem tonight. First I created an array and did
element-wise multiplication on it:
>>> a=zeros((3,3)) + eye(3)
>>> a*a
array([[ 1., 0., 0.],
[ 0., 1., 0.],
[ 0., 0., 1.]])
Then i assigned a value to one of the element:
>>> a[1,2]=4
Finally, the '*' operator was interpreted as a matrix multiplication
>>> a*a
array([[ 1., 0., 0.],
[ 0., 1., 16.],
[ 0., 0., 1.]])
The return types of zeros() and eye() are both arrays.
The even weird thing happened later. When I do the same thing in another
program (obtaining an adjacency matrix and computing graph powers), my
"matrix" was considered as an ''array."
So, why could an element assignment turn an array into a matrix? And
sometimes not?
Cheers, Forrest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110416/1400fe7b/attachment.html>
More information about the NumPy-Discussion
mailing list