Discussion: Introducing new operators for matrix computation

Huaiyu Zhu hzhu at localhost.localdomain
Thu Jul 13 15:47:23 EDT 2000


On Thu, 13 Jul 2000 12:33:49 GMT, Matt Feinstein <mfein at aplcomm.jhuapl.edu>
wrote: 
>
>My own preference would be 'as consistent as possible with MATLAB,
>with some caveats'-- this would mean option 1, with some thought about
>changes in places where the current MATLAB syntax drops the ball
>(IMO). I don't think MATLAB's inelegances should be preserved for the
>sake of consistency.

Any specific examples in mind?

> On the other hand, I think it's very important to
>make the translation from MATLAB language to Python as automatic as
>possible.

Agreed.  OTOH, it is forgone conclusion that we can't have both a\b and a/b.
So they have to be something similar to a/@b and a@/b.  That's my main
problem with option 1.  Using a fine symbol like \ as an escape marker looks
like a great waste to mathematicians but this has been with so many
programming languages for such a long time.

>The main thing I'd think about in addition to standard MATLAB syntax
>is a natural 'prolongation' syntax.

Are you thinking about this?
a = [1 2]
b = [3 4]
[a,b]  # [1 2 3 4]
[a;b]  # [1 2; 3 4]

Currently in MatPy we have the following, which is more general because no
special syntax is needed. But maybe we can find a better names?

Matrix_r([a,b])  
Matrix_c([a,b])

>One thing that MATLAB does correctly (again, IMO) is its relatively
>relaxed attitude towards distinctions among scalars, 1x1 vectors &
>matrices as well as among different kinds of nulls and NAN's. You can
>test for these distinctions if you want to, but generally MATLAB will
>just quietly do the right thing. There's a tendency to get wrapped up
>in fine distinctions in cases where there's really no ambiguity about
>what the programmer wants to do.

Right now in MatPy the distinction between 1x1 matrix and scalar is
maintained, intentionally.  So if size(x)==(3,1) then a*x works if a is
scalar but not if a is 1x1 matrix. I had had a fair bit of surprises in
matlab where something would work properly until someday it is given a
vector of length one, which is treated as a scalar.

On the other hand, there is no need to distinct vectors from 1xn and nx1
matrices and that's where we depart from NumPy.

Huaiyu



More information about the Python-list mailing list