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'
--billyb
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__
Unfortunately, there are still some bugs in the scalar multiplication section of _dotblas.c stemming from a re-write that allows discontiguous matrices. We are still tracking down the problems. Hopefully this should be fixed soon. -Travis
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. -Travis
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
I think it's time for a new release of NumPy. There have been several important bug-fixes and speed improvements recently. Please log any outstanding issues to the ticket system on http://projects.scipy.org/scipy/numpy/timeline I'd like to put another release out over the weekend. -Travis
Travis Oliphant schrieb:
I think it's time for a new release of NumPy. There have been several important bug-fixes and speed improvements recently.
Please log any outstanding issues to the ticket system on http://projects.scipy.org/scipy/numpy/timeline
Don't know if it qualifies as an outstanding issue, but may I ask about the status of making matrix decompositions (and ideally some other functions as well, like lstsq for example) preserve matrix types? Thanks much, Sven
Sven Schreiber wrote:
Travis Oliphant schrieb:
I think it's time for a new release of NumPy. There have been several important bug-fixes and speed improvements recently.
Please log any outstanding issues to the ticket system on http://projects.scipy.org/scipy/numpy/timeline
Don't know if it qualifies as an outstanding issue, but may I ask about the status of making matrix decompositions (and ideally some other functions as well, like lstsq for example) preserve matrix types?
We should be doing better in this regard. The __array_wrap__ is being applied (correctly now) in all the linalg functions, so that matrices are returned if they are used. All the ufuncs already preserve arguments. But, we should also peruse the code for asarray calls, save the __array_wrap__ method if available and wrap back the results so that types can be preserved. Someone spoke of writing a decorator to do that automatically which would indeed be nice. If you have examples of functions that are not being preserved, please report them. -Travis
Travis Oliphant wrote:
Someone spoke of writing a decorator to do that automatically which would indeed be nice.
As long as it's used in the 'old-fashioned' way (i.e., as func = decorator(func) and not @decorator func so that numpy remains 2.3-compatible. Just a heads-up so that 2.4-isms don't appear unintentionally. Cheers, f
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@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
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]])
participants (6)
-
Alan G Isaac
-
Bill Baxter
-
Fernando Perez
-
Sven Schreiber
-
Travis Oliphant
-
Travis Oliphant