我有两个清单
available_points = [[2,3], [4,5], [1,2], [6,8], [5,9], [51,35]]
和
solution = [[3,5], [2,1]]
我试图弹出一个点available_points
并将其附加到solution
从该点到所有点的欧几里得距离之和solution
最大的地方。
所以,我会得到这个
solution = [[3,5], [2,1], [51,35]]
我能够像这样选择最初的 2 个最远点,但不知道如何继续。
import numpy as np
from scipy.spatial.distance import pdist, squareform
available_points = np.array([[2,3], [4,5], [1,2], [6,8], [5,9], [51,35]])
D = squareform(pdist(available_points)
I_row, I_col = np.unravel_index(np.argmax(D), D.shape)
solution = available_points[[I_row, I_col]]
这给了我
solution = array([[1, 2], [51, 35]])