# Patterns extraction in time serie with DTW

I have a long time serie, let's say 1000 items. I want to find patterns in it of different lengths from 10 to 100 elements. To do this, I extract sliding windows of different lengths and calculate distance matrix between them using DTW. But it works very slowly. Can you please tell me if there is a more efficient method?

My code:

def generate_sliding_windows(series, window_size):
sliding_windows = []
for i in range(0, len(series) - window_size + 1):
window = tuple(series[i:i + window_size])
indexes = (i, i + window_size)
sliding_windows.append(
SlidingWindow(data=np.array(window), indexes=np.array(indexes))
)
return sliding_windows

sliding_windows = []
for window_size in range(10, 100):
sliding_windows.extend(
generate_sliding_windows(time_serie, window_size))

n = len(sliding_windows)
distance_matrix = np.zeros((n, n))
for i in range(n):
for j in range(i + 1, n):
dist = fastdtw(x, y, dist=euclidean)[0]
distance_matrix[i][j] = dist
distance_matrix[j][i] = dist


The slowest piece of code here is the calculation of the distance matrix.

Also, do you really want to calculate the distance between all possible subsequences of lengths 10 to 100? What will be the DTW distance between, say, the subsequences time_series[10:20] and time_series[10:21] and is this relevant to what you are trying to do?