Skip to content

Instantly share code, notes, and snippets.

@sa2812
Created July 25, 2017 07:32
Show Gist options
  • Save sa2812/1cc7889f10c4d340faf68cbe78fd94b9 to your computer and use it in GitHub Desktop.
Save sa2812/1cc7889f10c4d340faf68cbe78fd94b9 to your computer and use it in GitHub Desktop.
Strides with rolling window
def rolling_window(self, ts, window, stride):
shape = ts.shape[:-1] + (int((ts.shape[-1] - window)/stride + 1), window)
strides = (stride*ts.strides[-1],) + (ts.strides[-1],)
return np.lib.stride_tricks.as_strided(ts,
shape=shape,
strides=strides)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment