gen_idx_arange

nrv.eit.utils.gen_idx_arange(idx: ndarray | list, n: int, add_0: bool = False) ndarray[source]

Generate per-segment counters from boundary indices.

Note

this function returns a n-long list with a conter reset to 0 at each index in idx

Parameters:
  • idx (np.ndarray | list) – Sorted indices marking the start of new segments.

  • n (int) – Length of the output array.

  • add_0 (bool, optional) – If True, prepend a leading zero to the output.

Returns:

Counter resetting to zero at each segment boundary.

Return type:

np.ndarray

Example

>>> gen_idx_arange([1,4,6], 10)
array([0, 0, 1, 2, 0, 1, 0, 1, 2, 3])
>>> gen_idx_arange([3,6], 9)
array([0, 1, 2, 0, 1, 2, 0, 1, 2])
>>> gen_idx_arange([3,6], 9, True)
    array([0, 0, 1, 2, 0, 1, 2, 0, 1, 2])