mpl_interactions.nearest_idx

nearest_idx(array, value, axis=None)[source]

Return the index of the array that is closest to value. Equivalent to np.argmin(np.abs(array-value), axis=axis)

Parameters
  • array (arraylike)

  • value (Scalar)

  • axis (int, optional) – From np.argmin: “By default, the index is into the flattened array, otherwise along the specified axis.”

Returns

idx (IndexArray) – index of array that most closely matches value. If axis=None this will be an integer