[SciPy-user] Inconsistent function calls?
Thu May 21 10:19:13 CDT 2009
On Thu, May 21, 2009 at 10:46 AM, Ivo Maljevic <firstname.lastname@example.org> wrote:
> 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:
> 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
I regularly trip on missing ( ) for shape or size, but on the other
hand, you can use keyword arguments also as positional arguments,
which saves again on typing. I find the brackets inconvenient, but
since I start to write functions with flexible number of arguments,
requiring tuples reduces the ambiguity in the interpretation of the
numpy.ones(3) shouldn't produce a 2dim array, otherwise it would be
difficult to produce a one dimensional array of ones. matlab doesn't
have this problem, since it requires or creates almost always 2
My main problem in the syntax, when I switch back and forth between
matlab and python are  for array indices versus () in matlab. But I
think these syntactic differences are easy to adjust to, especially if
I get an instantaneous error message.
For me the main problems are the conceptional differences between
matlab and numpy, e.g. views, instead of copy on write, and some of
the fancy indexing behavior in numpy. We pay for the increased
flexibility of numpy compared to matlab with a steeper learning curve
and more bug hunting, at least I do.
> 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 <email@example.com>
>> 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.
>> 2009/5/21 Ivo Maljevic <firstname.lastname@example.org>:
>> > 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
>> > SciPyemail@example.com
>> > 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 mailing list
More information about the SciPy-user