我有2組2D點(A和B),每組有大約540點。我需要找到集合B是比定義的距離阿爾法遠離所有的點A.尋找蟒蛇中歐式距離的最快方法
我有一個解決方案的要點,但速度不夠快
# find the closest point of each of the new point to the target set
def find_closest_point(self, A, B):
outliers = []
for i in range(len(B)):
# find all the euclidean distances
temp = distance.cdist([B[i]],A)
minimum = numpy.min(temp)
# if point is too far away from the rest is consider outlier
if minimum > self.alpha :
outliers.append([i, B[i]])
else:
continue
return outliers
我使用Python 2.7與numpy和scipy。有沒有另外一種方法可以使我的速度大大提高?
在此先感謝您的答案
[兩個不同的Numpy數組中的點之間的歐氏距離的可能的重複,而不是](http://stackoverflow.com/questions/1871536/euclidean-distance-between-points-in-two-different-numpy-arrays -not-within)或[用numpy計算歐幾里德距離](http://stackoverflow.com/questions/1401712/calculate-euclidean-distance-with-numpy) –
由於你似乎只尋找離羣值,這是最近的鄰居搜索。我認爲你可以(也應該)使用'scipy.spatial.KDTree'(舊的cKDTree可能不支持這一點,所以在cKDTree中使用一個更新的scipy)。 – seberg
另外:http://stackoverflow.com/questions/19277244/fast-weighted-euclidean-distance-between-points-in-arrays/19285289#19285289 –