nearestindex

emlib.numpytools.nearestindex(a, grid, left=True, right=True)[source]

For each value in a return the index into grid nearest to it

To get the nearest element, do:

indexes = nearest_index(a, grid)
nearest_elements = grid[indexes]
Parameters:
  • a (ndarray) – events to match from. Does not need to be sorted

  • grid (ndarray) – events to match against. Does not need to be sorted

  • left – match events lower than the event from

  • right – match events higher than the event from

Return type:

ndarray