Skip to content

Instantly share code, notes, and snippets.

@syaffers
Last active June 18, 2020 21:04
Show Gist options
  • Save syaffers/ebb973672e85215e88c40699c4799b20 to your computer and use it in GitHub Desktop.
Save syaffers/ebb973672e85215e88c40699c4799b20 to your computer and use it in GitHub Desktop.
Vectorized version of sliding window extraction
def extract_windows_vectorized(array, clearing_time_index, max_time, sub_window_size):
start = clearing_time_index + 1 - sub_window_size + 1
sub_windows = (
start +
# expand_dims are used to convert a 1D array to 2D array.
np.expand_dims(np.arange(sub_window_size), 0) +
np.expand_dims(np.arange(max_time + 1), 0).T
)
return array[sub_windows]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment