[SciPy-user] Pros and Cons of Python verses other array environments

Bill Baxter wbaxter at gmail.com
Fri Sep 29 05:01:02 EDT 2006


On 9/29/06, Otto Tronarp <otto at tronarp.se> wrote:
> Quoting Bill Baxter <wbaxter at gmail.com>:
>
> > On 9/29/06, Otto Tronarp <otto at tronarp.se> wrote:
> >> This touches the subject of inconsistency with math.add as one
> >> example. One of my "favorite" peeve's is how the size (shape) is given
> >> to functions that generate matrices. In some functions the size is
> >> given as a tuple, in other the size in different dimensions are given
> >> as seperate arguments. Here are some examples:

> > eye(M,N) is considered to be ok, because 1-D eye is pretty useless,
> > and it's not clear what you'd want out of N-D identity matrix.
>
> That is valid point, but I would still argue for unified use of shape
> args. Assume that I have a function that does some calculations on a
> matrix and adds another like this:

Yeh, I don't disagree with you.  The other argument is that eye((3,3))
is more typing for interactive sessions, and seems weird to people
coming from matlab.  Why the extra parens?  Matlab generally accepts
either form for functions like that.

Personally I wrote my own versions of eye(), rand(), zeros(), ones(),
and empty() that work either with tuples or separate args.  I think
that's the best solution, but some folks here cringe at the thought of
overloading Python functions in that way.  It's true that overloading
is not very pretty in Python, but the users don't have to look at the
code in the library.  :-)  As long as it looks simple from the
outside.  (At least that's the C++ motto).

--bb



More information about the SciPy-User mailing list