maad.util.nearest_idx

maad.util.nearest_idx(array, value)[source]

Find nearest value on array and return its index.

Parameters:
array: ndarray-like of floats

array of values where to search the nearest values

value: float

value to be searched in array

Returns:
idx: int

index of nearest value on array

Examples

>>> x = np.array([1,2,3])
>>> maad.util.nearest_idx(x, 1.3)
    0
>>> maad.util.nearest_idx(x, 1.6)
    1