热线电话:13121318867

登录
2019-03-13 阅读量: 533
python如何计算两个物品的欧几里德距离

寻找欧几里德距离

两个向量x和y的广义欧几里德公式是这样的:

distance = sqrt{(x_{1}-y_{1})^2 + (x_{2}-y_{2})^2 + ... + (x_{n}-y_{n})^2}

代码:

def EuclideanDistance(x, y):

# The sum of the squared

# differences of the elements

S = 0;

for key in x.keys():

S += math.pow(x[key]-y[key], 2);

# The square root of the sum

return math.sqrt(S);

5.4951
2
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子