Created
March 31, 2018 23:34
-
-
Save duhaime/e4706906cf2ec57b9f82643c5cd405c0 to your computer and use it in GitHub Desktop.
Multidimensional sliding window in numpy
This file contains 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
import numpy as np | |
def get_windows(arr, window_size=64, step=32): | |
windows = [] | |
row = 0 | |
col = 0 | |
max_row, max_col = arr.shape | |
while row < max_row: | |
while col < max_col: | |
windows.append(arr[row:row+window_size, col:col+window_size]) | |
col += step | |
row += step | |
col = 0 | |
return windows | |
a = np.random.rand(4, 4) | |
windows = get_windows(a, window_size=2, step=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment