[Numpy-discussion] ndarray.T2 for 2D transpose
Chris Barker - NOAA Federal
chris.barker at noaa.gov
Wed Apr 6 11:44:19 EDT 2016
> I think that the problem is not that it doesn't raise an error for 1D array,
> but that it doesn't do anything useful to 1D arrays. Raising an error would
> change nothing to the way transpose is used now.
No, but it would make it clear that you can't expect transpose to make
a 1D array into a2D array.
> For a 1D array a of shape (N,), I expect a.T2 to be of shape (N, 1),
Why not (1,N)? -- it is not well defined, though I suppose it's not so
bad to establish a convention that a 1-D array is a "row vector"
rather than a "column vector".
But the truth is that Numpy arrays are arrays, not matrices and vectors.
The "right" way to do this is to properly extend and support the
matrix object, adding row and column vector objects, and then it would
be clear. But while there has been a lot of discussion about that in
the past, the fact is that no one wants it bad enough to write the
code.
So I think it's better to keep Numpy arrays "pure", and if you want to
change the rank of an array, you do so explicitly. I use:
A_vector.shape = (-1,1)
BTW, if transposing a (N,) array gives you a (N,1) array, what does
transposing a (N,1) array give you?
(1,N) or (N,) ?
-CHB
> which
> is useful when writing formulas, and clearer that a[None].T. Actually I'd
> like a.T to do that alreadu, but I guess backward compatibility is more
> important.
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> https://mail.scipy.org/mailman/listinfo/numpy-discussion
More information about the NumPy-Discussion
mailing list