[SciPy-user] Inconsistent function calls?
Thu May 21 10:49:12 CDT 2009
Yes, the copy problem is also something I always have to keep in mind, and
the explicit data type for ones and zeros.
As far as I am concerned, I have learned the differences and it is OK for
I guess my observation about the inconsistence is more of a philosophical
why bother to make something that looks like matlab, and than claim that it
meant to be that, except sometimes. Matplotlib does a pretty good job at
matlab plot functions, at least at the level I need it to.
I do not see any python imposed limitation at making ones(3,3) by default
what ones([3,3]) does, the same way random.rand(3,3) does, but if it was
things should be done the way they are, I can play by the rules, especially
since I am
aware of them.
BTW, the reason why I included that error message in my previous message is
I think it is completely non-helpful.
> On Thu, May 21, 2009 at 10:46 AM, Ivo Maljevic <email@example.com>
> > 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,
> > 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
> > you write
> > ones(3) and you get a vector instead of the expected 3x3 matrix. It is
> > thing to be
> > different because of implementation limitations, but this almost looks
> > 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
> > 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
> function arguments.
> 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
> dimensional arrays.
> 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
> > effort.
> > Ivo
> > 2009/5/21 Matthieu Brucher <firstname.lastname@example.org>
> >> 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 <email@example.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
> >> > brackets).
> >> >
> >> > It is not a big deal, but it seems a bit inconsistent for me.
> >> >
> >> > _______________________________________________
> >> > SciPy-user mailing list
> >> > SciPyfirstname.lastname@example.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
> >> SciPyemail@example.com
> >> http://mail.scipy.org/mailman/listinfo/scipy-user
> > _______________________________________________
> > SciPy-user mailing list
> > SciPyfirstname.lastname@example.org
> > http://mail.scipy.org/mailman/listinfo/scipy-user
> SciPy-user mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-user