1 回答

TA貢獻1780條經驗 獲得超4個贊
numpy的解決方案
首先準備數據
import numpy as np
x = np.array([[ 82, 210, 203, 234, 135, 92, 176, 146, 246, 35, 257, 227, 258,
132, 31, 160, 269, 24, 248, 274, 281, 279, 71, 21, 188, 163,
243],
[ 15, 16, 18, 18, 19, 21, 23, 29, 35, 47, 50, 53, 60,
64, 67, 69, 77, 88, 89, 91, 105, 115, 138, 175, 178, 205,
207]]).T
計算所有點對的距離
a,b = np.tril_indices(27, -1)
diss = np.linalg.norm(x[b] - x[a], axis=1)
找到距離小于閾值的點
distance = 10
near = x[np.unique(np.concatenate([b[diss < distance], a[diss < distance]]))]
然后我們可以繪制點
import matplotlib.pyplot as plt
plt.scatter(x[:,0], x[:,1])
plt.scatter(near[:,0], near[:,1]);
刪除點
remove = np.delete(x,np.unique(np.concatenate([b[diss < distance], a[diss < distance]])), axis=0)
plt.scatter(remove[:,0], remove[:,1]);
添加回答
舉報