snap_array

emlib.misc.snap_array(X, tick, offset=0.0, out=None, nearest=True)[source]

Snap the values of X to the nearest slot in a grid

Assuming a grid t defined by t(n) = offset + tick*n, snap the values of X to the nearest value of t

NB: tick > 0

Parameters:
  • X (ndarray) – an array

  • tick (float) – the step value of the grid

  • offset (float) – the offset of the grid

  • out (Optional[ndarray]) – if given, snapped values are placed in this array

  • nearest – if True, the nearest slot is selected. Otherwise the next lower (floor)

Return type:

ndarray

Returns:

an array containing the snapped values. This array will be out if it was given