I have been reading the tutorial of numpy i:j:k slicing at Scipy.org. After the second example, it says
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 - 1 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.
However:
>>> import numpy as np
>>> x = np.array([0,1,2,3,4])
>>> x[::-1]
array([4, 3, 2, 1, 0])
If j is defaulted to -1, then x[:-1:-1]
should be equivalent to x[::-1]
, but
>>> x[:-1:-1]
array([], dtype=int64)
>>> x[:-(len(x)+1):-1]
array([4, 3, 2, 1, 0])
while
>>> x[:-(len(x)+1):-1]
array([4, 3, 2, 1, 0])
So the default value of j when k < 0 should be -(n+1). And according to this post on stackoverflow, I believe the "official" default value of j when k < 0 is None
.
Am I misinterpreting the tutorial at SciPy.org?