[Numpy-discussion] index the last several members of a ndarray

Éric Depagne eric@depagne....
Tue Oct 18 06:56:33 CDT 2011


Le mardi 18 octobre 2011 13:44:00, Chao YUE a écrit :
> Dear all,
> 
> if I have
> 
> In [395]: a
> Out[395]:
> array([[0, 1, 2, 3, 4],
>        [5, 6, 7, 8, 9]])
> 
> In [396]: a[...,-1]
> Out[396]: array([4, 9])
> 
> In [397]: a[...,-4:-1]
> Out[397]:
> array([[1, 2, 3],
>        [6, 7, 8]])
> 
> In [398]: a[...,-4:0]
> Out[398]: array([], shape=(2, 0), dtype=int64)
> 
> how can I pick up something like:
> array([[1, 2, 3, 4],
>        [6, 7, 8, 9]])
> 
> I want to index the final 4 rows. I cannot figure out how to do this?
> 
Don't you want to do :
In [1]: a[:,-4:]
Out[1]: 
array([[1, 2, 3, 4],
       [6, 7, 8, 9]])

Éric.
> Thanks for any help,
> 
> Chao

Un clavier azerty en vaut deux
----------------------------------------------------------
Éric Depagne                            eric@depagne.org


More information about the NumPy-Discussion mailing list