i have the below table-like 6x3 numpy array:
array([[1, 4, 1],
[2, 2, 3],
[3, 5, 6],
[4, 8, 5],
[5, 2, 7],
[6, 4, 8]])
im trying to get rolling windows, say of size 4 (meaning, 4 rows at each window), such as below:
array([[[1, 4, 1],
[2, 2, 3],
[3, 5, 6],
[4, 8, 5]],
[[2, 2, 3],
[3, 5, 6],
[4, 8, 5],
[5, 2, 7]],
[[3, 5, 6],
[4, 8, 5],
[5, 2, 7],
[6, 4, 8]]])
what is a good efficient way of achieving this?
ultimately, i would like to build a function like this:
def rolling_windows(arr, windows_size):
return all windows of size "window_size" of the table-ish np.array "arr"
I tried to use np.lib.stride_tricks
, but unsuccessfuly...
thanks for your help