mrpro.utils.normalize_indices

mrpro.utils.normalize_indices(ndim: int, indices: int | Sequence[int] | None, *, unique: bool = True) tuple[int, ...][source]

Normalize each index in indices to the range [0, ndim).

Parameters:
  • ndim (int) – Number of dimensions.

  • indices (int | Sequence[int] | None) – One or more axis indices; negative indices count from the end. None means no indices -> empty tuple.

  • unique (bool, default: True) – If True (default), raise ValueError when normalized indices contain duplicates.

Returns:

Tuple of normalized indices in [0, ndim).

Raises:
  • IndexError – If any index is outside [-ndim, ndim).

  • IndexError – If unique is True and normalized indices are not unique.