[Numpy-discussion] ndarray.T2 for 2D transpose

Ian Henriksen insertinterestingnamehere at gmail.com
Mon Apr 11 20:25:10 EDT 2016


On Mon, Apr 11, 2016 at 5:24 PM Chris Barker <chris.barker at noaa.gov> wrote:

> On Fri, Apr 8, 2016 at 4:37 PM, Ian Henriksen <
> insertinterestingnamehere at gmail.com> wrote:
>
>
>> If we introduced the T2 syntax, this would be valid:
>>
>> a @ b.T2
>>
>> It makes the intent much clearer.
>>
>
> would:
>
> a @ colvector(b)
>
> work too? or is T2  generalized to more than one column? (though I suppose
> colvector() could support more than one column also -- weird though that
> might be.)
>
> -CHB
>

Right, so I've opted to withdraw my support for having the T2 syntax prepend
dimensions when the array has fewer than two dimensions. Erroring out in
the 1D
case addresses my concerns well enough. The colvec/rowvec idea seems nice
too, but it matters a bit less to me, so I'll leave that discussion open
for others to
follow up on. Having T2 be a broadcasting transpose is a bit more general
than any
semantics for rowvec/colvec that I can think of. Here are specific arrays
that, in
the a @ b.T2 can only be handled using some sort of transpose:

a = np.random.rand(2, 3, 4)
b = np.random.rand(2, 1, 3, 4)

Using these inputs, the expression

a @ b.T2

would have the shape (2, 2, 3, 3).

All the T2 property would be doing is a transpose that has similar
broadcasting
semantics to matmul, solve, inv, and the other gufuncs. The primary
difference
with those other functions is that transposes would be done as views
whereas the
other operations, because of the computations they perform, all have to
return new
output arrays.

Hope this helps,

-Ian Henriksen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20160412/ade6f77e/attachment.html>


More information about the NumPy-Discussion mailing list