[Numpy-discussion] .T Transpose shortcut for arrays again

Bill Baxter wbaxter at gmail.com
Thu Jul 6 09:48:59 CDT 2006


On 7/6/06, Tim Hochberg <tim.hochberg at cox.net> wrote:
>
> > -) Being able to distinguish between row and column vectors; I guess
> > this is just not possible with arrays...
> >
> Why can't you distinguish between them the same way that the matrix
> class does? Shape [1, N] is a row array, shape [N,1] is column array.


Yep, that works.  But there are still various annoyances.
- You have to remeber to specify extra brackets all the time.  Like
array([[1,2,3]]) or array([[1],[2],[3]]).
- And a slice of a vector out of a matrix has to be pumped back up to 2-D.
If x has ndim==2, then to get a column out of it you have to do x[:,i,None]
instead of just x[:,i].  To get a row you need x[j,None] instead of just
x[j]

Not horrible, but it feels a little klunky if you're used to something like
Matlab.

So matrix gets rid of a few annoyances like that ... and replaces them with
a few of its own.  :-)

--bb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060706/5b50ef5e/attachment.html 


More information about the Numpy-discussion mailing list