spiketools.utils.extract.get_ind_by_value¶
- spiketools.utils.extract.get_ind_by_value(values, value, threshold=None)[source]¶
Get the index for a set of values closest to a specified value.
- Parameters:
- values1d array
Values.
- valuefloat
The value to extract the index for.
- thresholdfloat, optional
The threshold that the closest value must be within to be returned. If the distance is greater than the threshold, output is -1.
- Returns:
- indint
The index value for the requested value, or -1 if out of threshold range.
Examples
Get the index for a specified value:
>>> values = np.array([5, 10, 15, 20, 25]) >>> get_ind_by_value(values, 12) 1