Skip to content

Instantly share code, notes, and snippets.

View theonegis's full-sized avatar

Victor Tan theonegis

View GitHub Profile
@theonegis
theonegis / sliding_window.py
Last active March 14, 2019 18:43
Use numpy to produce a view from a sliding, striding window over an array of arbitrary dimensions
def sliding_window_view(arr, window_shape, steps):
""" Produce a view from a sliding, striding window over `arr`.
The window is only placed in 'valid' positions - no overlapping
over the boundary.
Parameters
----------
arr : numpy.ndarray, shape=(...,[x, (...), z])
The array to slide the window over.