Skip to content

Instantly share code, notes, and snippets.

@PabTorre
Forked from sa2812/rolling_window.py
Created October 24, 2019 03:08
Show Gist options
  • Save PabTorre/418b59a9a460684cc00bd03222a2af0d to your computer and use it in GitHub Desktop.
Save PabTorre/418b59a9a460684cc00bd03222a2af0d 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