[Numpy-discussion] Matrix times scalar is wacky
Alan G Isaac
aisaac at american.edu
Fri Feb 24 06:15:12 CST 2006
On Fri, 24 Feb 2006, Bill Baxter apparently wrote:
> Multiplying a matrix times a scalar seems to return junk for some reason:
Confirmed.
Alan Isaac
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as N
>>> N.__version__
'0.9.5'
>>> a=N.array([[1,2],[3,4]],'f')
>>> b=N.mat(a)
>>> a*0.2
array([[ 0.2 , 0.40000001],
[ 0.60000002, 0.80000001]], dtype=float32)
#this works ok
>>> b*0.2
matrix([[ 0.2, 0.4],
[ 0.6, 0.8]])
>>> a = N.rand(1,2)
>>> b = N.mat(a)
>>> a*0.2
array([[ 0.01992175, 0.09690914]])
# this does not work ok
>>> b*0.2
matrix([[ 1.99217540e-002, 2.22617305e-309]])
>>>
More information about the Numpy-discussion
mailing list