[SciPy-user] Inconsistent function calls?
Ivo Maljevic
ivo.maljevic@gmail....
Thu May 21 10:49:12 CDT 2009
Josef,
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
me.
I guess my observation about the inconsistence is more of a philosophical
question:
why bother to make something that looks like matlab, and than claim that it
is not
meant to be that, except sometimes. Matplotlib does a pretty good job at
replicating
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
returning
what ones([3,3]) does, the same way random.rand(3,3) does, but if it was
decided
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
because
I think it is completely non-helpful.
Ivo
2009/5/21 <josef.pktd@gmail.com>
> On Thu, May 21, 2009 at 10:46 AM, Ivo Maljevic <ivo.maljevic@gmail.com>
> 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:
> >
> >>>> 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
>
> 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.
>
> Josef
>
> >
> > 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
> > effort.
> >
> > Ivo
> >
> >
> > 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
> >
> >
> > _______________________________________________
> > SciPy-user mailing list
> > SciPy-user@scipy.org
> > http://mail.scipy.org/mailman/listinfo/scipy-user
> >
> >
> _______________________________________________
> 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/8ec4983b/attachment.html
More information about the SciPy-user
mailing list