Skip to content

Instantly share code, notes, and snippets.

@cbpygit
Created April 8, 2020 08:03
Show Gist options
  • Save cbpygit/d4dc02f20c29cb6f05ba9946ddf33351 to your computer and use it in GitHub Desktop.
Save cbpygit/d4dc02f20c29cb6f05ba9946ddf33351 to your computer and use it in GitHub Desktop.
Find nearest value in numpy array
import numpy as np
def find_nearest(array, value):
array = np.asarray(array)
idx = (np.abs(array - value)).argmin()
return idx, array[idx]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment