[SciPy-user] Inconsistent function calls?

Ivo Maljevic ivo.maljevic@gmail....
Thu May 21 09:46:33 CDT 2009

I appreciate your argument that Python is not meant to to be Matlab, but
the learning curve is definitely less steep if the basic stuff works in a
similar fashion.
I do not have a problem with more esoteric functions working differently, as
I have to look them up
in Matlab as well as in Scipy.

I did not look at the history of this issue, but it can get confusing when
you write
ones(3) and you get a vector instead of the expected 3x3 matrix. It is one
thing to be
different because of implementation limitations, but this almost looks like
being different
for the sake of being different. Then, if you write ones(3,3) you get an
error message like this:

>>> numpy.ones(3,3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/dist-packages/numpy/core/numeric.py", line 1489,
in ones
    a = empty(shape, dtype, order)
TypeError: data type not understood

Don't get me wrong, I like very much what Scipy community is doing, and I
use every opportunity to mention to
other people that they can switch from Matlab to Python/Scipy without much


2009/5/21 Matthieu Brucher <matthieu.brucher@gmail.com>

> Hi,
> This is because ones(3,3) will be called with 3 as the first argument
> and 3 as the second argument, not with (3, 3) as the first argument.
> As the second argument is also used for something else, it is not even
> possible to detect if the second argument is an typo or a value for
> the matrix (for objects, it's not possible to choose).
> Python (a langage) is not meant to behave like Matlab (not a langage).
> This was also raised several months/years ago, you can browse the ML
> archives to find the discussion.
> Matthieu
> 2009/5/21 Ivo Maljevic <ivo.maljevic@gmail.com>:
> > Just as I was making up an example for the block diagonal matrix
> question, I
> > remembered the old problem I had with
> > consistency of nympy functions.
> >
> > If you want to generate a random number matrix, you can make the same
> call
> > as with matlab:
> >
> > rand(2,2) for 2x2 matrix,
> > randn(1,5) for 1x5 etc.
> >
> > but if you want to generate ones or zeros matrices, you cannot say
> > ones(3,3), you have to write ones([3,3]) or zeros([3,3]) (note the extra
> > brackets).
> >
> > It is not a big deal, but it seems a bit inconsistent for me.
> >
> > _______________________________________________
> > SciPy-user mailing list
> > SciPy-user@scipy.org
> > http://mail.scipy.org/mailman/listinfo/scipy-user
> >
> >
> --
> Information System Engineer, Ph.D.
> Website: http://matthieu-brucher.developpez.com/
> Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92
> LinkedIn: http://www.linkedin.com/in/matthieubrucher
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20090521/cb38f545/attachment.html 

More information about the SciPy-user mailing list