how to do circular shift in numpy how to do circular shift in numpy arrays arrays

how to do circular shift in numpy


Why not just roll with a negative number?

>>> import numpy as np>>> a = np.arange(10)>>> np.roll(a,2)array([8, 9, 0, 1, 2, 3, 4, 5, 6, 7])>>> np.roll(a,-2)array([2, 3, 4, 5, 6, 7, 8, 9, 0, 1])


you can use negative shift

a = np.arange(10)print(np.roll(a, 3))print(np.roll(a, -3))

returns

[7, 8, 9, 0, 1, 2, 3, 4, 5, 6]
[3, 4, 5, 6, 7, 8, 9, 0, 1, 2]