[Numpy-discussion] Syntax Improvement for Array Transpose

Hameer Abbasi einstein.edison at gmail.com
Sun Jun 23 15:51:49 EDT 2019


+1 for this. I have often seen (and sometimes written) code that does this automatically, and it is a common mistake.

However, we will need some way to filter for intent, as the people who write this code are the ones who didn’t read docs on it at the time, and so there might be a fair amount of noise even if it fixes their code.

I also agree that a transpose of an array with ndim > 2 doesn’t make sense without specifying the order, at least for the applications I have seen so far.

Get Outlook for iOS<https://aka.ms/o0ukef>

________________________________
From: NumPy-Discussion <numpy-discussion-bounces+einstein.edison=gmail.com at python.org> on behalf of Eric Wieser <wieser.eric+numpy at gmail.com>
Sent: Sunday, June 23, 2019 9:24 PM
To: Discussion of Numerical Python
Subject: Re: [Numpy-discussion] Syntax Improvement for Array Transpose

This might be contentious, but I wonder if, with a long enough deprecation cycle, we can change the meaning of .T. That would look like:

* Emit a future warning on `more_than_2d.T` with a message like "in future .T will transpose just the last two dimensions, not all dimensions. Use are.transpose() if transposing all {n} dimensions is deliberate"
* Wait 5 releases or so, see how many matches Google / GitHub has for this warning.
* If the impact is minimal, change .T
* If the impact is large, change to a deprecation warning

An argument for this approach: a good amount of code I've seen in the wild already assumes T is a 2d transpose, and as a result does not work correctly when called with stacks of arrays. Changing T might fix this broken code automatically.

If the change would be too intrusive, then keeping the deprecation warning at least prevents new users deliberately using .T for >2d transposes, which is possibly valuable for readers.

Eric


On Sun, Jun 23, 2019, 12:05 Stewart Clelland <stewartclelland at gmail.com<mailto:stewartclelland at gmail.com>> wrote:
Hi All,

Based on discussion with Marten on github<https://github.com/numpy/numpy/issues/13797>, I have a couple of suggestions on syntax improvements on array transpose operations.

First, introducing a shorthand for the Hermitian Transpose operator. I thought "A.HT<http://A.HT>" might be a viable candidate.

Second, the adding an array method that operates like a normal transpose. To my understanding,
"A.tranpose()" currently inverts the usual order of all dimensions. This may be useful in some applications involving tensors, but is not what I would usually assume a transpose on a multi-dimensional array would entail. I suggest a syntax of "A.MT<http://A.MT>" to indicate a transpose of the last two dimensions by default, maybe with optional arguments (i,j) to indicate which two dimensions to transpose.

I'm new to this mailing list format, hopefully I'm doing this right :)

Thanks,
Stew
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion at python.org<mailto:NumPy-Discussion at python.org>
https://mail.python.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20190623/8f7cff40/attachment.html>


More information about the NumPy-Discussion mailing list