79141847

Date: 2024-10-30 15:47:52
Score: 0.5
Natty:
Report link

The way you're currently doing it, the efficiency is O(N⋅M), which isn't very efficient.

You could try:

def find_nearest_vectorized(a, b):
   a = a[:, np.newaxis]
   diff = np.abs(a - b)
   indexes = np.argmin(diff, axis=0)
   return indexes
Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Spix737