【发布时间】:2013-10-20 09:13:28
【问题描述】:
我有 2 组 2D 点(A 和 B),每组大约有 540 个点。我需要找到集合 B 中与 A 中所有点的定义距离 alpha 远的点。
我有一个解决方案,但不够快
# 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
我正在使用带有 numpy 和 scipy 的 python 2.7。是否有另一种方法可以使我的速度显着提高?
提前感谢您的回答
【问题讨论】:
-
因为您似乎只寻找异常值,这是最近邻搜索。我认为你可以(并且应该)使用
scipy.spatial.KDTree(旧的 cKDTree 可能不支持,所以在 cKDTree 支持的地方使用更新的 scipy)。
标签: python numpy scipy euclidean-distance