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

Devin Jeanpierre jeanpierreda at gmail.com
Sun Mar 23 11:51:24 CET 2014


On Sun, Mar 23, 2014 at 3:40 AM, Sturla Molden <sturla.molden at gmail.com> wrote:
> On 15/03/14 01:09, Antoine Pitrou wrote:
>
>> Really? That should be up to the third-party library implementing the @
>> operator for its types, not to the language itself: Python _suggests_
>> an use case for @, it doesn't mandate it (especially as there's no
>> appropriate data type in the stdlib).
>
>
> array.array is an appropriate type for supporting @ for matrix
> multiplication.

I was thinking the function type, as a composition operator. Matrix
multiplication corresponds exactly with composition of linear
functions, so it makes some sort of sense. And it has some kind of
neat similarity to decorators, which generalize function composition.

If you rename "matmul" to "compose" and "matpow" to something like
"iterate" (except less confusing), then you've generalized the
operators a little and given them more potential use cases.

-- Devin


More information about the Python-ideas mailing list