I have an original array, e.g.:
import numpy as np
original = np.array([56, 30, 48, 47, 39, 38, 44, 18, 64, 56, 34, 53, 74, 17, 72, 13, 30, 17, 53])
The desired output is an array made up of a fixed-size window sliding through multiple iterations, something like
[56, 30, 48, 47, 39, 38],
[30, 48, 47, 39, 38, 44],
[48, 47, 39, 38, 44, 18],
[47, 39, 38, 44, 18, 64],
[39, 38, 44, 18, 64, 56],
[38, 44, 18, 64, 56, 34],
[44, 18, 64, 56, 34, 53],
[18, 64, 56, 34, 53, 74],
[64, 56, 34, 53, 74, 17],
[56, 34, 53, 74, 17, 72]
At the moment I'm using
def myfunc():
return np.array([original[i: i+k] for i in range(i_range)])
with parameters i_range = 10
and k = 6
, using python's timeit module (10000 iter), I'm getting close to 0.1 seconds. Can this be improved 100x by any chance?
I've also tried Numba but the result wasn't ideal, as it shines better with larger arrays.
NOTE: the arrays used in this post are reduced for demo purpose, actual size of original
is at around 500.