[Numpy-discussion] indexing question

John Salvatier jsalvati@u.washington....
Sun Nov 21 13:29:55 CST 2010


read about basic slicing :
http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html

On Sun, Nov 21, 2010 at 11:28 AM, John Salvatier
<jsalvati@u.washington.edu> wrote:
> yes use the symbol ':'
>
> so you want
>
> t[:,x,y]
>
> 2010/11/21 Ernest Adrogué <eadrogue@gmx.net>:
>> Hi,
>>
>> Suppose an array of shape (N,2,2), that is N arrays of
>> shape (2,2). I want to select an element (x,y) from each one
>> of the subarrays, so I get a 1-dimensional array of length
>> N. For instance:
>>
>> In [228]: t=np.arange(8).reshape(2,2,2)
>>
>> In [229]: t
>> Out[229]:
>> array([[[0, 1],
>>        [2, 3]],
>>
>>       [[4, 5],
>>        [6, 7]]])
>>
>> In [230]: x=[0,1]
>>
>> In [231]: y=[1,1]
>>
>> In [232]: t[[0,1],x,y]
>> Out[232]: array([1, 7])
>>
>> This way, I get the elements (0,1) and (1,1) which is what
>> I wanted. The question is: is it possible to omit the [0,1]
>> in the index?
>>
>> Thanks in advance.
>>
>> --
>> Ernest
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>


More information about the NumPy-Discussion mailing list