find_idx_nearest_val

halotools.utils.find_idx_nearest_val(array, value)[source] [edit on github]

Method returns the index where the input array is closest to the input value.

Parameters:

array : array_like

value : float or int

Returns:

idx_nearest : int

Notes

Use of this function is deprecated. The numpy.argmin function provides equivalent behavior.

Examples

>>> x = np.linspace(0, 1000, num=int(1e5))
>>> val = 45.5
>>> idx_nearest_val = find_idx_nearest_val(x, val)
>>> nearest_val = x[idx_nearest_val]