[SciPy-user] should vectorize honor array/matrix distinctions?

Carlos Scheidegger cscheid@sci.utah....
Thu Mar 15 13:04:24 CDT 2007


Hi,

should scipy.vectorize honor array/matrix distinctions?

http://www.scipy.org/NumPy_for_Matlab_Users claims "[returning an array when
given a matrix] shouldn't happen with NumPy functions (if it does it's a
bug)". However, this is what I get on my amd64 ubuntu edgy box:

$ python
Python 2.4.4c1 (#2, Oct 11 2006, 20:00:03)
[GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>> import numpy
>>> scipy.__version__
'0.5.1'
>>> numpy.__version__
'1.0rc1'
>>> import math
>>> def v(x): return int(math.log(abs(x) * 10.0, 10.0))
...
>>> m = scipy.matrix([[1.0, 5.0], [5.0, 10.0]])
>>> a = scipy.array([[1.0, 5.0], [5.0, 10.0]])
>>> vv = scipy.vectorize(v)
>>> vv(m)
array([[1, 1],
       [1, 2]])
>>> vv(a)
array([[1, 1],
       [1, 2]])
>>> type(m)
<class 'numpy.core.defmatrix.matrix'>
>>> type(a)
<type 'numpy.ndarray'>
>>> type(vv(m))
<type 'numpy.ndarray'>
>>> type(vv(a))
<type 'numpy.ndarray'>

Is this expected behavior? I know there are trivial workarounds, but I just
wanted to clarify.

FWIW, I'm using the universe numpy package. Thank you very much for your time,
-carlos


More information about the SciPy-user mailing list