[Numpy-discussion] index the last several members of a ndarray
Chao YUE
chaoyuejoy@gmail....
Tue Oct 18 06:56:48 CDT 2011
Thanks Jean
I just want the last several numbers by indexing from the end.
In [400]: b=np.arange(20).reshape(2,10)
In [401]: b
Out[401]:
array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19]])
I want something like b[...,...(index from the end by using negative
number)] to get:
array([[ 6, 7, 8, 9],
[16, 17, 18, 19]])
but it's strange that if you use b[...,-1],
you get:
In [402]: b[...,-1]
Out[402]: array([ 9, 19])
if use b[...,-4:-1],
you get:
Out[403]:
array([[ 6, 7, 8],
[16, 17, 18]])
but you cannot use b[...,-4:-1] to get
array([[ 6, 7, 8, 9],
[16, 17, 18, 19]])
because
In [403]: b[...,-4:-1]
Out[403]:
array([[ 6, 7, 8],
[16, 17, 18]])
I don't know I am more clear this time....
Chao
2011/10/18 Jean-Luc Menut <jeanluc.menut@free.fr>
> how can I pick up something like:
>> array([[1, 2, 3, 4],
>> [6, 7, 8, 9]])
>>
>
>
> I'm not sure to understand, should not a[:,1:] be sufficient ?
> Did I miss something in your message ?
>
>
--
***********************************************************************************
Chao YUE
Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)
UMR 1572 CEA-CNRS-UVSQ
Batiment 712 - Pe 119
91191 GIF Sur YVETTE Cedex
Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16
************************************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20111018/18f65189/attachment.html
More information about the NumPy-Discussion
mailing list