Avoid NaNs in correlation distance in bad cases
@@ -311,6 +311,9 @@ def correlation(x, y):
norm_y += shifted_y ** 2
dot_product += shifted_x * shifted_y
+ if dot_product == 0.0:
+ return 1.0
+ else:
return (1.0 - dot_product) / np.sqrt(norm_x * norm_y)
named_distances = {
