I have 2, 2D NumPy arrays consisting of ~300,000 (x,y) pairs each. Given the ith (x, y) pair in array A, I need to find the corresponding jth (x,y) pair in array B such that ([xi - xj]2 + [yi - yj]2)½, the distance between the two (x,y) pairs, is minimized.
What I'm currently doing is argmin
like so:
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]])
Is there a faster way to accomplish this?