1

Is there a numpy-thonic way to get the nearest values between two arrays:

Example:

a = np.array([1, 2, 3, 4, 5, 6, 7, 8])
b = np.array([1.1, 3.2, 4.9, 7.2])
c = find_nearests(a, b)

c would be the size of b with the nearest elements from a:

print(c)
([1, 3, 5, 7])

This question is a direct reference to the following one that applies for searching one element in a tab: Find nearest value in numpy array

n0n0bstan
  • 1,790
  • 4
  • 15
  • 26

0 Answers0