NumArray array-indexing

Michael Drumheller drumheller at alum.mit.edu
Mon Aug 16 03:05:26 EDT 2004


Christopher T King <squirrel at WPI.EDU> wrote in message news:<Pine.LNX.4.44.0408121444370.9594-100000 at ccc8.wpi.edu>...
> On Thu, 12 Aug 2004, Christopher T King wrote:
> 
> > On 12 Aug 2004, Michael Drumheller wrote:
> > 
> > > Basically, it seems to me that NumArray simply does not support
> > > the distinction between a column vector and a row vector.  That 
> > > is, if you have x=[1,2,3], then transpose(x) is a no-op.  True?
> > 
> > False.  You have to supply numarray with a two-dimensional array in order 
> > to perform a two-dimensional transpose:
> 
> Where by "False" I meant "The first sentence is false, but the second 
> sentence is true".  Column vectors and row vectors must be represented as 
> two-dimensional arrays; transpose() of a one-dimensional array is a no-op 
> since all transpose() does (by default) is reverse the order of the axes.

I understand that, but I think it just goes to support my contention that
NumArray does not support transposed vectors *from an array-indexing point
of view.*  Here is what I mean:

As you pointed out in your previous message, you can get "the transpose
of a row vector" if the "row vector" is actually a single-row matrix,
i.e.,

>>> transpose([[1, 2, 3]])
array([[1],
       [2],
       [3]])

However, whereas [1, 2, 3] passed as an index-array will get you the
second, third, and fourth rows of a rank-2 matrix, [[1,2,3]] will *not*
do that.  (It gets you some other weird thing that I can't remember.)
That is, a single-row matrix may be the same thing as a row vector
in a mathematical context, but it is not the same thing in an
array-indexing context.  Similarly, passing [[1],
                                             [2],
                                             [3]]
as an index array doesn't get you anything remotely like the second
third, and fourth columns.  So it seems to me that array indexing
can easily get you an arbitrary subset of rows, but not an arbitrary
subset of columns.  Would you agree?
By the way:  Thank you for your attention to my problem!
Mike



More information about the Python-list mailing list