find_nearest_indices
- ssapy.utils.find_nearest_indices(A, B)[source][source]
Finds the indices of the nearest values in array A for each value in array B.
Parameters:
A (array-like): A 1D array or list of values to search within. B (array-like): A 1D array or list of values for which the nearest values in A are to be found.
Returns:
numpy.ndarray: A 1D array of indices corresponding to the nearest values in A for each value in B.
Notes:
This function uses broadcasting to compute the absolute differences between each element in B and all elements in A.
The nearest value is determined by finding the index of the minimum absolute difference.
If there are multiple values in A equally close to a value in B, the index of the first occurrence is returned.
Example:
>>> import numpy as np >>> A = np.array([1, 3, 7, 10]) >>> B = np.array([2, 8]) >>> find_nearest_indices(A, B) array([1, 2]) # Nearest values are A[1] (3) for B[0] (2) and A[2] (7) for B[1] (8).