bundles / numpy 2.4.3 / numpy / lib / array_utils / normalize_axis_index
built-in
numpy.lib.array_utils:normalize_axis_index
Signature
built-in
normalize_axis_index ( axis , ndim , msg_prefix = None ) Summary
Normalizes an axis index, axis, such that is a valid positive index into the shape of array with ndim dimensions. Raises an AxisError with an appropriate message if this is not possible.
Extended Summary
Used internally by all axis-checking logic.
Parameters
axis: intThe un-normalized index of the axis. Can be negative
ndim: intThe number of dimensions of the array that
axisshould be normalized againstmsg_prefix: strA prefix to put before the message, typically the name of the argument
Returns
normalized_axis: intThe normalized axis index, such that
0 <= normalized_axis < ndim
Raises
: AxisErrorIf the axis index is invalid, when
-ndim <= axis < ndimis false.
Examples
import numpy as np from numpy.lib.array_utils import normalize_axis_index normalize_axis_index(0, ndim=3) normalize_axis_index(1, ndim=3) normalize_axis_index(-1, ndim=3)✓
normalize_axis_index(3, ndim=3) normalize_axis_index(-4, ndim=3, msg_prefix='axes_arg')✓
Aliases
-
numpy.fft._pocketfft.normalize_axis_index