[Numpy-discussion] Possible new multiplication operators for Python

Alan G Isaac aisaac at american.edu
Mon Aug 18 19:31:45 EDT 2008


> On Mon, Aug 18, 2008 at 12:21, Charles R Harris  <charlesr.harris at gmail.com> wrote:
>> Tim Hochberg proposed using the call operator for matrix multiplication, 
>> i.e., 
>> A(B(C))


Robert Kern wrote:
> It's certainly worth exploring. My personal opinion is that I could 
> just use a single operator for doing matrix multiplication. I don't 
> want to see two variants of every single operator. 


User opinion on Tim's proposal:
it is not bad, especially if you write
A(B)(C) instead of A(B(C)).
But in the end I think it looks acceptable
only if you do not plan to use matrices much.
For teaching purposes: I think it fails
for not being explicit enough.
I would even prefer A.dot(B).dot(C) for this reason.
But I prefer a normal binary multiplication operator!

User opinion on Robert's comment:
I agree.

I use matrix powers and so would
feel some loss there, but I could
accept say M.pow(n) instead of M**n.

So it seems to me, as a user,
that the SciPy community should
definitely ask for a way to have
a distinct matrix multiplication operator.

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)?
Maybe.

Propsal 5: use the existing language, either
using __call__ as in Tim's proposal or adding
a ``dot`` method.

Did I miss any?

As PEP 225 notes, implementing proposals 1 or 2
does not rule out future interest in proposal 4.

Cheers,
Alan Isaac





More information about the NumPy-Discussion mailing list