计算多个点中距离最远的两个点 python

import numpy as np
from scipy import spatial


print("hello")
# test points
pts = np.random.rand(100, 2)
print(pts)
# two points which are fruthest apart will occur as vertices of the convex hull
candidates = pts[spatial.ConvexHull(pts).vertices]
# get distances between each pair of candidate points
dist_mat = spatial.distance_matrix(candidates, candidates)
# get indices of candidates that are furthest apart
i, j = np.unravel_index(dist_mat.argmax(), dist_mat.shape)
print(candidates[i], candidates[j])
# e.g. [ 1.11251218e-03 5.49583204e-05] [ 0.99989971 0.99924638]
原文地址:https://www.cnblogs.com/ziytong/p/11188122.html