python计算两个向量之间的欧氏距离
程序员文章站
2022-03-31 23:33:15
...
python计算两个向量之间的欧氏距离
代码:
import numpy as np
# 向量的值
feature_1 = np.array([1,2,3])
feature_2 = np.array([14,15,16])
def embedding_distance(feature_1, feature_2):
dist = np.linalg.norm(feature_1 - feature_2)
return dist
dis = embedding_distance(feature_1, feature_2)
print('feature_1,feature_1的欧式距离为',dis)
效果:
feature_1,feature_1的欧式距离为 22.516660498395403