Discussion: Introducing new operators for matrix computation

Huaiyu Zhu hzhu at localhost.localdomain
Thu Jul 13 17:23:28 EDT 2000


On Thu, 13 Jul 2000 13:18:37 -0600, Bjorn Pettersen <bjorn at roguewave.com>
wrote: 

>It seems like you're trying to create a special purpose language here.
>Ie. I don't see it as general enough to be worth putting into the core
>unless you can come up with other use cases... Personally, I would much
>prefer the ability to overload the relational operators (individually,
>not through __cmp__).

This is not a call for a special language for matrix only.  But we do need
enough binary operators to override with.  The additional operators might be
useful at other places as well.

In matlab the following operations are all different from each other

a+b        a.+b  
a-b        a.-b
a*b        a.*b
a/b        a./b
a\b        a.\b
a^b        a.^b

What python operators can we override for them all? Just one additional
symbol for so many new binary operators is a good bargain, IMO.

I think cleanness is one of the main virtue of python, but it is lacking in
numerical computation.  To give an example of the difference it makes, I'll
quote from my original post asking for matrix in python (with corrections)

[in octave we write]
> b = X\y                  # LMS solution of a linear equation y = X*b
> b = (X'*X)\(X'*y)        # or written out in more details
> b = inv(X'*X)*(X'*y)     # or in a less efficient form.
> 
> but the corresponding Python notation is horrendous:
> 
> b = matrixmultiply(inverse(matrixmultiply(transpose(X), X)), 
>     (matrixmultiply(transpose(X), y[:,NewAxis])))


Doesn't this look like the other p language or lisp?  Well, my original post
missed two parentheses and two matrixmultiply's and nobody even noticed it.
If one cannot even write X\y in one line, think about how to write a typical
formula like

B = inv(A) - A\U/(C+V/A*U)*V/A


Huaiyu



More information about the Python-list mailing list