I have 6 timeseries data as follows namely t1, t2, t3, t4, t5 and t6.
import numpy as np
series = np.array([
[0., 0, 1, 2, 1, 0, 1, 0, 0],
[0., 1, 2, 0, 0, 0, 0, 0, 0],
[1., 2, 0, 0, 0, 0, 0, 1, 1],
[0., 0, 1, 2, 1, 0, 1, 0, 0],
[0., 1, 2, 0, 0, 0, 0, 0, 0],
[1., 2, 0, 0, 0, 0, 0, 1, 1]])
I want to create a euclidean distance matrix from these 6 timeseries as in the format of (i.e. 6*6 where x
denotes the corresponding euclidean distance):
t1 t2 t3 t4 t5 t6
t1 0 x x x x x
t2 x 0 x x x x
t3 x x 0 x x x
t4 x x x 0 x x
t5 x x x x 0 x
t6 x x x x x 0
I am currently constructing this matrix manually as follows (In this SO question: Efficient and precise calculation of the euclidean distance this method has got the hightest performance).
e.g., to calculate euclidean distance between t3 and t6.
def eudis(v1, v2):
dist = [(a - b)**2 for a, b in zip(v1, v2)]
dist = math.sqrt(sum(dist))
return dist
eudis(t3, t6)
However, I am sure that there could be more easy and computationally efficient way to do this in python. Please let me know if you have suggestions.
I am happy to provide more details if needed.