Operators for matrix: current choices (Was Matlab vs Python ...)

Tim Hochberg tim.hochberg at ieee.org
Wed Jul 19 00:33:18 EDT 2000


Paul Prescod <paul at prescod.net> writes:

> Tim Hochberg wrote:
> > 
> > Similarly:
> > 
> > dot((A,B), C) -> A(B)(C)
> > dot(A, dot(B,C) -> A(B(C))
> > 
> > which looks pretty good to me. And it's arguably closer to paper
> > linear algebra notation than A*B is.
> 
> Another good idea! You can even make it look like the new-syntax
> proposal:
> 
> A()*B()*C
> A()+B()+C
> A()-B()-C

I suppose you could, although what I had in mind was specific to
Matrix multiplication. I went ahead and added it to JNumeric, just for
grins, and I still think it looks pretty good. Maybe I'll keep it and
see if the CNumeric people will follow.

An example:

>>> from Numeric import *
>>> a = arange(5)
>>> a(a)
30
>>> a
array([0, 1, 2, 3, 4])
>>> b = identity(5)
>>> b
array([[1, 0, 0, 0, 0],
       [0, 1, 0, 0, 0],
       [0, 0, 1, 0, 0],
       [0, 0, 0, 1, 0],
       [0, 0, 0, 0, 1]])
>>> b(a)
array([0, 1, 2, 3, 4])
>>> b*a
array([[0, 0, 0, 0, 0],
       [0, 1, 0, 0, 0],
       [0, 0, 2, 0, 0],
       [0, 0, 0, 3, 0],
       [0, 0, 0, 0, 4]])
>>> (b*a)(a)
array([ 0,  1,  4,  9, 16])
>>>  # For those of you who like the more symmetrical look.
>>> (a)(a)
30
>>> (b)(a)
array([0, 1, 2, 3, 4])
>>>     


It's easier to do than to explainily yours,

-tim



More information about the Python-list mailing list