problems with duplicating and slicing an array

Steven Bethard steven.bethard at gmail.com
Fri Jan 21 14:44:30 EST 2005


py> import numarray as na
py> a = na.array([[1,2,3],[4,5,6]])

Yun Mao wrote:
>   Thanks for the help. numarray doesn't provide what I look for either. e.g. 
> a = array( [[1,2,3],[4,5,6]] )
> I sometimes what this:  a[ [1,0], :],

py> a[[1,0]]
array([[4, 5, 6],
        [1, 2, 3]])

> or even a[ [1,0], [0,1] ] , which should give me
> [[4, 5], [1,2]]

py> a[:,:2][[1,0]][[0,1]]
array([[4, 5],
        [1, 2]])

Not the same syntax, of course, but doable.

Steve



More information about the Python-list mailing list