[Numpy-discussion] Backwards slicing including the first element
esteve at lkb.ens.fr
Wed Mar 10 08:33:55 EST 2010
Is there a way to give an integer value to j when using a[i:j:-1] so that the first element of the array can be included in the slice ?
I would like to use some code like a[i:i-k:-1] to get a slice of length k.
The numpy documentation seems to suggest that j=-1 should work:
"Assume n is the number of elements in the dimension being sliced. Then, if i is not given it defaults to 0 for k > 0 and n for k < 0 . If j is not given it defaults to n for k > 0 and -1 for k < 0 . If k is not given it defaults to 1."
But a[i:i-k:-1] is empty if i-k is -1. The workaround is a[i::-1][:k], is there something simpler ?
Many thanks in advance, Jerome.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion