Euclidean distance with weights

I am currently using SciPyto compute Euclidean distance

dis = scipy.spatial.distance.euclidean(A,B)

Where; A, B are 5-bit bit vectors. Now it works fine, but if I add weights for each dimension, can I use scipy?

What I have now: sqrt((a1-b1)^2 + (a2-b2)^2 +...+ (a5-b5)^2)

I want: sqrt(w1(a1-b1)^2 + w2(a2-b2)^2 +...+ w5(a5-b5)^2)use scipy or numpy or any other effective way to do this.

thank

+5
source share
2 answers

The proposal to write your own weighted norm L2 is good, but the calculation presented in this answer is incorrect. If the intention is to calculate

enter image description here

then this should complete the task:

def weightedL2(a,b,w):
    q = a-b
    return np.sqrt((w*q*q).sum())
+8
source

. - :

def mynorm(A, B, w):
    import numpy as np
    q = np.matrix(w * (A - B))
    return np.sqrt((q * q.T).sum())
+1

All Articles