[Numpy-discussion] [RFC] should we argue for a matrix power operator, @@?

Nathaniel Smith njs at pobox.com
Sat Mar 15 22:12:08 EDT 2014


On Sat, Mar 15, 2014 at 1:13 PM, Alan G Isaac <alan.isaac at gmail.com> wrote:
> On 3/15/2014 12:32 AM, Nathaniel Smith wrote:
>>   I know you were worried
>> about losing the .I attribute on matrices if switching to ndarrays for
>> teaching -- given that ndarray will probably not get a .I attribute,
>> how much would the existence of @@ -1 affect you?
>
> Not much. Positive integer powers would be useful
> (for illustrating e.g. graph theory and difference equations),
> but not enough to delay the PEP.

So to be clear, even if numpy.matrix is going away, and even if
ndarray isn't getting a .I attribute, then you're just as happy
typing/teaching inv(X) as X @@ -1?

> I think NumPy should "take the money and run".
> Getting `@` is great.  Let's get experience with
> it before deciding whether it's worth asking for `@@`.
>
> Questions for `@@`:
> - would it just be `matrix_power`, with all the restrictions?
> - or would `a(10,2,2)@@-1` return an array of matrix inverses?
> - etc

The version in the PEP does do gufunc-style broadcasting for >2d
arrays, yes. So will np.linalg.matrix_power as soon as someone bothers
to send a patch ;-)

> In the end, I'd like to see a functional implementation before
> deciding on `@@`, but I would not like to see `@` delayed at all.

Oh, well, not much is going to affect `@`'s timing, unless we're
*dreadfully* slow. Py 3.5 isn't even scheduled yet b/c 3.4 isn't out,
and IIUC Python's standard release cycle is 18 months. So we've got a
year+ before feature freeze, regardless.

-n

-- 
Nathaniel J. Smith
Postdoctoral researcher - Informatics - University of Edinburgh
http://vorpus.org



More information about the NumPy-Discussion mailing list