[Numpy-discussion] Matrix times scalar is wacky

Bill Baxter wbaxter at gmail.com
Wed Mar 8 15:40:03 EST 2006


Workarounds I know of are:

    asmatrix(scalar * m.A)

or I noticed the other day that scalar division works ok, so if you know
scalar is != 0,

    m / (1.0/scalar)

where m is a numpy.matrix, of course.

I find myself repeatedly getting bitten by this, since I'm writing code that
does lots of lerping between vectors.
This is pretty dang ugly to see all over the place:
   vlerp = asmatrix((1-t) * v1.A + t * v2.A)
when it should just be
   vlerp = (1-t)*v1 + t*v2
yeh yeh, I should write a function...
--bb


On 3/9/06, Sven Schreiber <svetosch at gmx.net> wrote:
>
> Travis Oliphant schrieb:
> > Bill Baxter wrote:
> >
> >> Multiplying a matrix times a scalar seems to return junk for some
> reason:
> >>
> >> >>> A = numpy.asmatrix(numpy.rand(1,2))
> >> >>> A
> >> matrix([[ 0.30604211,  0.98475225]])
> >> >>> A * 0.2
> >> matrix([[  6.12084210e-002,   7.18482614e-290]])
> >> >>> 0.2 * A
> >> matrix([[  6.12084210e-002,   7.18482614e-290]])
> >> >>> numpy.__version__
> >> '0.9.5'
> >>
> > This should be fixed in SVN.
> >
> >
> I have just been bitten by this bug, so I would like to ask when to
> expect the next release. And/or are there any workarounds?
>
> Thanks,
> Sven
>



--
William V. Baxter III
OLM Digital
Kono Dens Building Rm 302
1-8-8 Wakabayashi Setagaya-ku
Tokyo, Japan  154-0023
+81 (3) 3422-3380
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060308/2864ccad/attachment-0001.html>


More information about the NumPy-Discussion mailing list