If you want to do this manually, just use np.tile
:
import numpy as np a = np.array([1,2,3])
Replicate it to the tile, but again than necessary to get the desired "shift"
b = np.tile(a, a.size+1)
Then change it so that it is a 2D matrix with the form (a, a+1)
b.reshape(a.size, a.size+1) #[[1 2 3 1] # [2 3 1 2] # [3 1 2 3]]
Well, that was just a debugging step to see what was going on. But if you see this, you know that you just need to delete the last column:
b.reshape(a.size, a.size+1)[:,:-1]
And then you have the desired result.
This can also be generalized to allow (almost) arbitrary shifts:
shift = 3 a = np.array([...]) b = np.tile(a, a.size+shift) res = b.reshape(a.size, a.size+shift)[:,:-shift]
source share