[Numpy-discussion] ndarray.T2 for 2D transpose
Todd
toddrjen at gmail.com
Wed Apr 6 13:43:15 EDT 2016
On Tue, Apr 5, 2016 at 11:14 PM, Nathaniel Smith <njs at pobox.com> wrote:
> On Tue, Apr 5, 2016 at 7:11 PM, Todd <toddrjen at gmail.com> wrote:
> > When you try to transpose a 1D array, it does nothing. This is the
> correct
> > behavior, since it transposing a 1D array is meaningless. However, this
> can
> > often lead to unexpected errors since this is rarely what you want. You
> can
> > convert the array to 2D, using `np.atleast_2d` or `arr[None]`, but this
> > makes simple linear algebra computations more difficult.
> >
> > I propose adding an argument to transpose, perhaps called `expand` or
> > `expanddim`, which if `True` (it is `False` by default) will force the
> array
> > to be at least 2D. A shortcut property, `ndarray.T2`, would be the same
> as
> > `ndarray.transpose(True)`.
>
> An alternative that was mentioned in the bug tracker
> (https://github.com/numpy/numpy/issues/7495), possibly by me, would be
> to have arr.T2 act as a stacked-transpose operator, i.e. treat an arr
> with shape (..., n, m) as being a (...)-shaped stack of (n, m)
> matrices, and transpose each of those matrices, so the output shape is
> (..., m, n). And since this operation intrinsically acts on arrays
> with shape (..., n, m) then trying to apply it to a 0d or 1d array
> would be an error.
>
>
My intention was to make linear algebra operations easier in numpy. With
the @ operator available, it is now very easy to do basic linear algebra on
arrays without needing the matrix class. But getting an array into a state
where you can use the @ operator effectively is currently pretty verbose
and confusing. I was trying to find a way to make the @ operator more
useful.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20160406/15579e7b/attachment.html>
More information about the NumPy-Discussion
mailing list