Slice objects with negative increment

Paul Hughett hughett at mercur.uphs.upenn.edu
Tue Apr 30 16:01:29 EDT 2002


Alex Martelli <aleax at aleax.it> wrote:

:> Alex Martelli <aleax at aleax.it> wrote:

:>>> r=Numeric.array(range(13))

:>>> r[-3::]
: array([10, 11, 12])
:>>> r[-3::-1]
: array([10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0])
:>>>

Hmm.  Is the value of r[-1:-1:-1] equal to array([12, 11, 10, 9, 8, 7,
6, 5, 4, 3, 2, 1, 0]) or to an empty array?  It could plausibly be
either, depending on whether the middle -1 is interpreted as a lower
limit or as 1 from the end.

In any case, I will be adopting the Numeric convention.  As you point
out, having multiple conventions is definitely a bad idea.


Paul Hughett



More information about the Python-list mailing list