[Numpy-discussion] indexing question
Todd Miller
jmiller at stsci.edu
Sat Mar 27 13:57:51 EST 2004
On Sat, 2004-03-27 at 12:05, Faheem Mitha wrote:
> Dear People,
>
> Suppose I create a numarray arry (say). A numeric array would be fine
> too; it probably does not matter.
>
> >>>import numarray
> >>>foo = numarray.reshape(numarray.arange(9),(3,3))
> array([[ 0, 1, 2, 3],
> [ 4, 5, 6, 7],
> [ 8, 9, 10, 11],
> [12, 13, 14, 15]])
>
> Is there some way to select the indexes corresponding only to (say)
> two rows or columns?
>
> ie suppose I just want the first and the fourth row or the first and
> third columns? Is there some clean way to do this which does not
> involve extracting individual rows or columns?
>
> Ie. I want something like
> >>> foo[?,:]
> array([[ 0, 1, 2, 3],
> [12, 13, 14, 15]])
>
Try foo[[0,2]]. Note that the array indexing syntax is a little picky:
foo[(0,2)] (tuple index) won't work, just foo[[0,2]] (list index) or
foo[array([0,2])] (array index).
Regards,
Todd
> etc.
>
> Suggestions appreciated. Please cc me; I'm not subscribed. Thanks in
> advance.
>
> Faheem.
>
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: IBM Linux Tutorials
> Free Linux tutorial presented by Daniel Robbins, President and CEO of
> GenToo technologies. Learn everything from fundamentals to system
> administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
--
Todd Miller <jmiller at stsci.edu>
More information about the NumPy-Discussion
mailing list