[Numpy-discussion] problems with duplicating and slicing an array

Chris Barker Chris.Barker at noaa.gov
Fri Jan 21 14:57:48 CST 2005


Simon Burton wrote:
> On Thu, 20 Jan 2005 20:29:26 -0500
> Yun Mao <yunmao at gmail.com> wrote:

>>2. Is there a way to do Matlab style slicing? e.g. if I have 
>>  i = array([0, 2])
>>  x = array([1.1, 2.2, 3.3, 4.4])
>>  I wish y = x(i) would give me [1.1, 3.3]
> 
> have a look at the "take" method.

or use numarray:

 >>> import numarray as N
 >>> i = N.array([0, 2])
 >>> x = N.array([1.1, 2.2, 3.3, 4.4])
 >>> y = x[i]
 >>> y
array([ 1.1,  3.3])
 >>>



-- 
Christopher Barker, Ph.D.
Oceanographer
                                     		
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov




More information about the Numpy-discussion mailing list