import numpy as np 方法一 def Distance(vec1,vec2): dist = np.sqrt(np.sum(np.square(vec1 - vec2))) return dist 方法二 def distEclud(vecl1,vecl2): dist = np.sqrt(np.sum(np.power(vecl1 - vecl2,2))) return dist v1 = [1,2] v2 = [2,3] v1 = np.array(v1) v2 = np.array(v2) print(Distance(v1,v2)) print(distEclud(v1,v2))