First I have a scalar time series stored in a numpy array:
ts = np.arange(10)
which is
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
Suppose I want to extract from ts a series of vectors (2,1,0), (3,2,1), (4,3,2), etc., I can think of the following code to do it:
for i in range(len(ts)-2):
print(ts[2+i:i-1:-1])
However, when i=0, the above code returns an empty array rather than [2,1,0] because the loop body will become
print(ts[2:-1:-1])
where the -1 in the middle creates trouble.
My question is: is there a way to make the indexing work for [2,1,0]?