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

Travis Oliphant oliphant at ee.byu.edu
Fri Jan 21 15:37:49 EST 2005


Chris Barker wrote:

>
>
> 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])
> >>>
>
>

Or use scipy:

from scipy import *
alter_numeric()

i = array([0,2])
x = array([1.1,2.2,3.3,4.4])
y = x[i]

print y
[1.1  3.3]








More information about the NumPy-Discussion mailing list