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);






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论