python自带库
import math
def get_distance(p1, p2):
return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
print(get_distance((0, 0), (1, 1)))
numpy方法
import numpy as np
def get_distance_np(p1, p2):
pp1 = np.array(p1)
pp2 = np.array(p2)
return np.linalg.norm(pp1-pp2)
print(get_distance((0, 0), (1, 1)))