Last active
June 18, 2020 21:04
-
-
Save syaffers/ebb973672e85215e88c40699c4799b20 to your computer and use it in GitHub Desktop.
Vectorized version of sliding window extraction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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