[Numpy-discussion] Syntax Improvement for Array Transpose

Marten van Kerkwijk m.h.vankerkwijk at gmail.com
Tue Jun 25 10:05:08 EDT 2019


Hi Juan,

On Tue, Jun 25, 2019 at 9:35 AM Juan Nunez-Iglesias <jni.soma at gmail.com>
wrote:

> On Mon, 24 Jun 2019, at 11:25 PM, Marten van Kerkwijk wrote:
>
> Just to be sure: for a 1-d array, you'd both consider `.T` giving a shape
> of `(n, 1)` the right behaviour? I.e., it should still change from what it
> is now - which is to leave the shape at `(n,)`.
>
>
> Just to chime in as a user: v.T should continue to be a silent no-op for
> 1D arrays. NumPy makes it arbitrary whether a 1D array is viewed as a row
> or column vector, but we often want to write .T to match the notation in a
> paper we're implementing.
>
> More deeply, I think .T should never change the number of dimensions of an
> array.
>

OK, that makes three of you, all agreeing on the same core argument, but
with you now adding another strong one, of not changing the number of
dimensions. Let's consider this aspect settled.


>
> I'm ambivalent about the whole discussion in this thread, but generally I
> think NumPy should err on the side of caution when deprecating behaviour.
> It's unclear to me whether the benefits of making .T transpose only the
> last two dimensions outweigh the costs of deprecation. Despite some
> people's assertion that those using .T to transpose >2D arrays are probably
> making a mistake, we have two perfectly correct uses in scikit-image. These
> could be easily changed to .transpose() (honestly they probably should!),
> but they illustrate that there is some amount of correct code out there
> that would be forced to keep up with an update here.
>

Fair enough, there are people who actually read the manual and use things
correctly! Though, being generally one of those, I still was very
disappointed to find `.T` didn't do the last two axes.

Any preference for alternative spellings?

All the best,

Marten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20190625/5d846e12/attachment.html>


More information about the NumPy-Discussion mailing list