[Python-Dev] Matrix product
Fredrik Johansson
fredrik.johansson at gmail.com
Wed Jul 30 02:59:36 CEST 2008
On Wed, Jul 30, 2008 at 2:26 AM, Guido van Rossum <guido at python.org> wrote:
> On Fri, Jul 25, 2008 at 6:50 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>> Sebastien Loisel wrote:
>>
>>> What are the odds of this thing going in?
>>
>> I don't know. Guido has said nothing about it so far this
>> time round, and his is the only opinion that matters in the
>> end.
>
> I'd rather stay silent until a PEP exists, but I should point out that
> last time '@' was considered as a new operator, that character had no
> uses in the language at all. Now it is the decorator marker. Therefore
> it may not be so attractive any more.
I don't like @.
> I understand that you can't use A*B as matrix multiplication because
> it should mean elementwise multiplication instead, just like A+B is
> elementwise addition (for matrixes, as opposed to Python sequences).
>
> But would it be totally outlandish to propose A**B for matrix
> multiplication? I can't think of what "matrix exponentiation" would
> mean...
http://mathworld.wolfram.com/MatrixExponential.html :-)
In fact Mathematica uses ** to denote general noncommutative
multiplication (though . for matrix multiplication in particular).
However, this wouldn't solve the problem, because an important reason
to introduce a matrix multiplication operator is to distinguish
between matrix and elementwise operations for arrays. The ** operator
already denotes the obvious elementwise operation in numpy.
Further, while A**B is not so common, A**n is quite common (for
integral n, in the sense of repeated matrix multiplication). So a
matrix multiplication operator really should come with a power
operator cousin.
Matlab uses * for matrix and .* for elementwise multiplication.
Introducing .* for elementwise multiplication in Python would not be
compatible with existing numpy code, and introducing .* with the
reversed meaning of Matlab would be *very* confusing :-)
Maple uses &* for matrix multiplication. However, Maple's syntax is
not a good style reference for anything.
Besides those alternatives and the regular *, I don't know any other
ASCII operators used by existing mathematical software for matrix
multiplication. Well, Fortress probably has some unicode symbol for it
(I suppose that would be one desperate possibility).
Fredrik
More information about the Python-Dev
mailing list