NumArray array-indexing

Christopher T King squirrel at WPI.EDU
Thu Aug 12 20:40:30 CEST 2004

On 12 Aug 2004, Michael Drumheller wrote:

> I am new to NumArray and I wonder if someone can help me with
> array-indexing.  Here's the basic situation: Given a rank-2 array
> (i.e., a matrix) it seems to be trivial, with array indexing,
> to extract a subset of its *columns*.  But it does not seem
> to be trivial to extract a subset of its *rows*.

You can do this using slices, like so:

>>> from numarray import *
>>> a = array([[1, 2], [3, 4]])
>>> a[:,1]
array([2, 4])

':' means 'take all values along this axis', just like how with standard 
Python lists it means 'take all values in the list'.

> 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:

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

More information about the Python-list mailing list