[Numpy-discussion] New Operators in Python

Beliavsky beliavsky@aol....
Sun Mar 25 12:51:33 CDT 2007


On Mar 24, 3:48 pm, "Charles R Harris" <charlesr.har...@gmail.com>
wrote:

> > It is somewhat workable as it stands, but I think it would be nicer if
> > we could have some "meta" operator that allowed an alternative
> > definition of major operators.   Something like @*  for example (just
> > picking a character that is already used for decorators).
>
> Yes indeed, this is an old complaint. Just having an infix operator would be
> an improvement:
>
> A dot B dot C

In Fortran 90 and later versions, A*B means element-wise
multiplication, and there exist intrinsic functions such as
matmul(A,B) and dot_product(A,B). One can define operators so that

A .x. B .x. C

is the same as matmul(A,matmul(B,C))

although I am unsure of the order of operations implied by the former
syntax. The Matran http://www.cs.umd.edu/~stewart/matran/Matran.html
package does this. I think Fortran's infix operators are a good
solution but don't know if it can be carried over to Python.



More information about the Numpy-discussion mailing list