Created
April 8, 2020 08:03
-
-
Save cbpygit/d4dc02f20c29cb6f05ba9946ddf33351 to your computer and use it in GitHub Desktop.
Find nearest value in numpy array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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