[Numpy-discussion] Possible new multiplication operators for Python
Wed Aug 20 09:31:36 CDT 2008
On Tuesday 19 August 2008, Alan G Isaac wrote:
> Proposal 1: PEP 225, but *just* for multiplication.
> Either ~* as in the PEP or @* (which I prefer).
> (This looks simplest.)
> Proposal 2: PEP 225
> (but maybe using @ instead of ~).
> Proposal 3: use of a unicode character,
> perhaps × since it is in the Latin1
> extension of ASCII.
> Proposal 4: user defined operators, perhaps
> as described in PEP 225.
> In this case, @dot would be a natural.
> (This looks most complex but also most powerful.)
> But is A @dot B really better than say A.dot(B)?
> Propsal 5: use the existing language, either
> using __call__ as in Tim's proposal or adding
> a ``dot`` method.
> Did I miss any?
You could abuse Python's current capabilities to create something that
looks like proposal 4:
C = A *dot* B
You would need a helper object named "dot". This has been proposed on
the Python-Dev list. I find this kinds of pseudo operator a bit
clunky. It might be quite confusing to beginners because really the
the "*" operator is invoked twice.
The pseudo operator has one nice aspect: It can take additional
arguments, which could be nice for the array-of-matrices application.
mmul = dot((1,0),(0,1))
C = A *mmul* B
I'd like PEP 225 to be implemented. The new operators are kind of
elegant, and they don't introduce any new concepts. They just
introduce a bunch of new special functions.
More information about the Numpy-discussion