Discussion: Introducing new operators for matrix computation

Gregory Lielens gregory.lielens at fft.be
Fri Jul 14 05:31:55 EDT 2000


John Lull wrote:
> 
> At the dawn of the third millenium (by the common reckoning),
> hzhu at localhost.localdomain (Huaiyu Zhu) wrote (with possible
> deletions):
> 
> > 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])))
> 
> I'm don't think this is quite fair.  You could just as easily write:
>     b = rDiv(X, y)
> if you simply had an appropriate rDiv() function.  It's not nearly as
> pretty as octave's notation, but it doesn't have to be nearly as
> hideous as your example.

Indeed, but it is the old choice between functional/operator notation...
For example, the second expression, b = (X'*X)\(X'*y), would be in
functional notation 
something like b=rDiv(Mul(X.T(),X),Mul(X.T(),y))
This is ok, but imho far more error prone than operator notation,
because 
- all linear algebra textbooks present expressions with operator
notation
- the operator notation is more natural to almost everybody when dealing
with arithmetic

I personnaly consider that linear algebra is an extension of simple
arithmetic, almost on the same level as complex numbers (and usefull to
the same kind of people which could use complex numbers). 
The fact that complex numbers are part of built-in python types and can
be manipulated using standard arithmetic operators plead for a similar
facility for linear algebra, imho. 

But contrary to complex numbers, easy manipulation of matrices ideally
require more than the usual +,-,*,/, because of the lack of
commutativity (therefore the introduction of left and right divide) and
the usefullness of both elementwise and matrix operations.

Should something a "elementwise" complex multiplication
c=a*b=Complex(Real(a)*Real(b),Imag(a)*Imag(b))  (*)
have any usage, maybe the initial design of python would have included
two multiplication operators...


Greg.



(*) Please, never implement this horror!!!



More information about the Python-list mailing list