numpy roll
import numpy as np from scipy.ndimage.interpolation import shift xs = np.array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]) shift(xs, 3, cval=np.NaN)
Here is what the above code is Doing:
1. Create an array of 10 numbers from 0 to 9.
2. Shift the array by 3.
3. Fill the empty spaces with NaN.
The result is:
array([ NaN, NaN, NaN, 0., 1., 2., 3., 4., 5., 6.])