Function adas.i4indf
def i4indf(array, value, side=None)
-
Find the index of the 1-D array closest to the requested value.
Parameters
array
:numpy array
value
:int, float
- value for which index is required.
side
:str
- if 'left' ensure that the returned index is for a value less than value. If 'right' ensure that the index is for a value greater than the requested value. Do not apply if the index is at the start or end of the array.
Returns
index
:int
- index of quantity in array closest to value.
Notes
A python version of an ADAS routine. The numpy equivalent is np.abs(array-value).argmin() which is non obvious.
The optional side parameter is to move the returned index to be that of the array value that is definitely less than or greater than the requested value rather than the array element closest in value.
Version History
- Martin O'Mullane, 20-10-2017
- First version
- Martin O'Mullane, 18-07-2023
- Add side parameter
Example
>>> import adas as adas >>> result = np.array([2.3, 5.5, 8.5, 12.0, 41.2]) >>> adas.i4indf(result, 9.0) 2