Why does a[1:-1:-1] with a=[1,2,3] return []?
List[1:-1:-1] means List[start index : end index : jump]
Indexing in List:




Number
1
2
3




Index
0
1
2


Index
-3
-2
-1




So, if we take list a[1,2,3] and find list of a[1:-1:-1] means starting index = 1, ending index = -1, jump = -1
So, list traversing through the

index 1 (i.e. number=2) to index -1 (i.e. number=3) but jump = -1 (means backward position)


So, return an empty list i.e. []
I am observing that if a is a list (or a numpy array) with elements [1,2,3] and I ask for a[1:-1:-1], then I get the empty list. I would expect to get [2,1] assuming that the slicing spans the indexes obtainable decrementing from 1 to -1 excluding the last value (that is excluding -1), that is indexes 1 and 0.
The actual behavior may have some justification but makes things more complex than expected when one needs to take a subarray of an array a starting from some generic index i to index i+m (excluded) in reverse order. One would tend to write a[i+m-1:i-1:-1] but this suddenly breaks if i is set to 0. The fact that it works for all i but zero looks like a nasty inconsistency. Obviously, there are workarounds:

one could write a[i+m-1-n:i-1-n:-1] offsetting everything by -n where n is the array length; or
one could write a[i:i+m][::-1].

However, in case 1 the need to know the array length appears rather unnatural and in case 2 the double indexing appears as a not very justified overhead if the slicing is done in a tight loop.

Is there any important reason that I am missing for which it is important that the behavior is as it is?

Has this issue been considered by the NumPy community?

Is there some better workaround than those I came up with?