[Python-ideas] [RFC] draft PEP: Dedicated infix operators for matrix multiplication and matrix power

Nathaniel Smith njs at pobox.com
Fri Mar 14 15:55:06 CET 2014


On Fri, Mar 14, 2014 at 1:20 PM, M.-A. Lemburg <mal at egenix.com> wrote:
> On 14.03.2014 12:25, Robert Kern wrote:
>> On 2014-03-14 10:16, M.-A. Lemburg wrote:
>>
>>> I have some questions:
>>>
>>> 1. Since in math, the operator is usually spelt "·" (the center dot,
>>>     or "." but that's already reserved for methods and attributes in
>>>     Python), why not try to use that instead of "@" (which in Python
>>>     already identifies decorators) ?
>>
>> I think the current feeling of the Python core team is against including non-ASCII characters in the
>> language's keywords or operators. Even if that were not so, I would still recommend against it
>> because it would be quite difficult to type. I don't know off-hand the key combination to do it on
>> my native system, and it would change from system to system.
>
> That's a fair argument. How about using the degree symbol instead: "°" ?
>
> (A ° B).T == B.T ° A.T

Well, obviously we can bikeshed this all day :-). For reasons the
draft PEP goes into in more detail, what we need is a symbol that
means "matrix rather than scalar/elementwise multiplication", and
there is no existing conventional symbol (either in math or
programming) that has that meaning -- \cdot, \degree, etc. don't have
that meaning any more than @ does. So we have to make something up.

My feeling is that @ is the least-bad option, and -- as the person
who's maybe been staring at these code samples the longest -- I found
that I got used to it pretty quickly. But I don't think debating is
going to lead to any "obviously best" answer, at some point we'll just
have to pick something. So maybe it's more useful to focus more on the
other parts of the proposal? :-)

-n


More information about the Python-ideas mailing list