create a function of a set of integers and a value for which you need to find the nearest one.
def find_nearest(array, value): array = np.asarray(array) idx = (np.abs(array-value)).argmin() return array[idx] find_nearest(np.array([0, 2.1, 4.3, 6.5, 8.8, 11.0]), 1.5)