2

我有 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。还有另一种方法可以使我的速度大大提高吗?

提前感谢您的答案

4

2 回答 2

4
>>> from scipy.spatial.distance import cdist
>>> A = np.random.randn(540, 2)
>>> B = np.random.randn(540, 2)
>>> alpha = 1.
>>> ind = np.all(cdist(A, B) > alpha, axis=0)
>>> outliers = B[ind]

给你你想要的分数。

于 2013-10-20T09:46:48.347 回答
0

如果您有一组非常大的点,您可以计算 a 加减 aplha 的 x 和 y 边界,然后从位于该边界之外的特定考虑中消除 b 中的所有点。

于 2013-10-20T10:19:37.443 回答