I am trying to construct two sliding windows over a multivariate sequence of data (m*n). The first window should be fixed and the second one is rolling over the data samples. Both windows have the same size. I followed this postdistance calculations, FFT, Sliding window and built upon that. I am struggling to implement it. The python snippet of the code is below:
sliding_dist(data,window_size):
window_size = 10
n = len(data)
dist = np.zeros(n)
for i in range(n - window_size):
fixed_window = data[i:window_size, :]
rolling_window = data[i:i + window_size,:]
ditance = np.linalg.norm(fixed_window - rolling_window)
dist[i] = ditance
return dist
My problem is how to fix the first window and keep the second on rolling over data sample n. Logically, I am not quite sure whether the implementation of for loop and indexes are correct or should I change them. Also, I have issue with the indexes I got an error about the shape: ValueError: operands could not be broadcast together with shapes (9,3) (10,3)
Edit:
I just edited the code to take the fixed window out of the for loop. It solved the previous error ValueError: operands could not be broadcast together with shapes (9,3) (10,3) :
sliding_dist(data,window_size):
window_size = 10
n = len(data)
dist = np.zeros(n)
fixed_window = data[:window_size, :]
for i in range(n - window_size):
rolling_window = data[i:i + window_size,:]
ditance = np.linalg.norm(fixed_window - rolling_window)
dist[i] = ditance
return dist
I am still not sure about whether the way I implemented the two sliding windows is correct or not? Please could anyone have some thoughts and help on this.