Following-up from this question years ago, is there a canonical \"shift\" function in numpy? I don\'t see anything from the documentation.
Here\'s a simple version o
You can also do this with Pandas:
Using a 2356-long array:
import numpy as np
xs = np.array([...])
Using scipy:
from scipy.ndimage.interpolation import shift
%timeit shift(xs, 1, cval=np.nan)
# 956 µs ± 77.9 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
Using Pandas:
import pandas as pd
%timeit pd.Series(xs).shift(1).values
# 377 µs ± 9.42 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
In this example, using Pandas was about ~8 times faster than Scipy