I have a 64x64
numpy array and I have a 5x64
window. I want to slide this window over the main numpy array with a step size of 1
and save the values that lie in that window in a column in an empty numpy array.
Thanks
I have a 64x64
numpy array and I have a 5x64
window. I want to slide this window over the main numpy array with a step size of 1
and save the values that lie in that window in a column in an empty numpy array.
Thanks
Exactly as you said in the comment, use the array index and incrementally iterate. Create a list (a
in my case) to hold your segmented windows (window
). In the end, use np.hstack
to concatenate them.
import numpy as np
yourArray = np.random.randn(64,64) # just an example
winSize = 5
a = [] # a python list to hold the windows
for i in range(0, yourArray.shape[0]-winSize+1):
window = yourArray[i:i+winSize,:].reshape((-1,1)) # each individual window
a.append(window)
result = np.hstack(a)