1

I have two lists of points stored as rows of 2d arrays:

a = np.array([[1, 2], [3, 4], [5, 6]])
b = np.array([[1, 2], [3, 4]])

For each point in b, I would like to get the indices of the nearest point in a. Currently, my solution is

f = lambda x: np.argmin(np.linalg.norm(a - x, axis=1))
print(list(map(f, b)))

Is there a more efficient way to do this? I have tried np.vectorize(f)(b), but it does not work.

W. Zhu
  • 755
  • 6
  • 16

0 Answers0