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

Tim Hochberg tim.hochberg at cox.net
Thu Jul 6 10:45:13 CDT 2006

Bill Baxter wrote:
> On 7/6/06, *Tim Hochberg* <tim.hochberg at cox.net 
> <mailto: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]]). 
This one I can't get excited about. If you are actually creating that 
many constant arrays, just define rowarray and colarray functions that 
add the appropriate dimensions for you.

> - 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]
Alternatively x[:,i:i+1], although that's not much better.

> Not horrible, but it feels a little klunky if you're used to something 
> like Matlab.
Well Matlab is geared to matrices. The ndarray object has always been 
more or less a tensor. I can't help feeling that loading it up with 
matrix like methds is just going to lead to confusion and trouble. I 
would rather work things out so that we can have a pure matrix class and 
a pure ndarray class coexist in some sensible way. Figuring out how to 
do that well would have fringe benefits for other stuff (masked arrays, 
sparse arrays, user defined arrays of various types).
> So matrix gets rid of a few annoyances like that ... and replaces them 
> with a few of its own.  :-)
In theory matrix should not be annoying to Matlab users since it's whole 
purpose is to keep matlab users happy. I think the big problem with 
matrix is that none of the developers use it as far as I know, so no one 
is motivated to clean up the rough edges.


More information about the Numpy-discussion mailing list