Is there a numpy-thonic way, e.g. function, to find the nearest value in an array?
Example:
np.find_nearest( array, value )
For 2d array, to determine the i, j position of nearest element:
import numpy as np def find_nearest(a, a0): idx = (np.abs(a - a0)).argmin() w = a.shape[1] i = idx // w j = idx - i * w return a[i,j], i, j