如何使用numpy配对(x,y)对

AJ *_*dge 5 python arrays search numpy bisection

我有2个2D NumPy数组,每个数组由〜300,000(x,y)对组成。给定数组A中的 i (x,y)对,我需要找到数组B中的 j (x,y)对,使得([x i -x j ] 2 + [y i -y j ] 2½(两个(x,y)对之间的距离)最小。

我目前正在做的是argmin这样的:

thickness = []
for i in range(len(A)):
    xi = A[i][0]
    yi = A[i][1]
    idx = (np.sqrt(np.power(B[:, 0] - xi, 2) + np.power(B[:, 1] - yi, 2))).argmin()
    thickness.append([(xi + B[idx][0]) / 2, (yi + B[idx][1]) / 2,
                      A[i][2] + B[idx][2]])
Run Code Online (Sandbox Code Playgroud)

有没有更快的方法可以做到这一点?