import numpy as np
def euclidean_distance(vec1, vec2):
'''欧氏距离'''
return np.linalg.norm(vec1-vec2)
def cosine_similarity(vec1, vec2):
'''向量夹角的余弦值'''
return np.dot(vec1,vec2)/(np.linalg.norm(vec1)*(np.linalg.norm(vec2)))
def angle(vec1, vec2, degree=False):
'''向量夹角,通过degree=True切换弧度制到角度制'''
angle = np.arccos(np.dot(vec1,vec2)/(np.linalg.norm(vec1)*(np.linalg.norm(vec2))))
if degree:
angle = angle*180/np.pi
return angle