The code below finds the Euclidean distance between each element of list a and each element of list b.
from scipy.spatial import distance
a = [[1, 2, 3], [4, 5, 6]]
b = [[10, 20]]
Final_distance = []
for i in [j for sub in a for j in sub]:
for k in [m for t in b for m in t]:
dist = distance.euclidean(i, k)
Final_distance.append(dist)
print(Final_distance)
The output is
[9.0, 19.0, 8.0, 18.0, 7.0, 17.0, 6.0, 16.0, 5.0, 15.0, 4.0, 14.0]
But for very large list it is taking very long time. Is there a way to reduce the time complexity of the above code?