so I was wondering if there is some trickery with slices that would allow me to do cyclic permutations of an array. Basically what I want to do know if there are integers i,j,k such that:
> x = np.arange(10)
> print x[i:j:k]
[9,0,1,2,3,4,5,6,7,8]
and
> x = np.arange(10)
> print x[i:j:k]
[1,2,3,4,5,6,7,8,9,0]
I thought the natural syntax would be:
import numpy as np
x = np.arange(10)
print x[-1:0]
but that returns an empty array (and it kinda makes sense…). Also tried other combinations of slices and nothing worked. I could do it in other ways, but this would be so neat and short… 😛
Thanks.
You could use
numpy.roll()or some stride tricks, but other than that I’m pretty sure the answer is no, there is no 3-integer slice that will return what you want.