You are viewing an older version (2.4.3). Go to latest (2.4.4)
{ } Raw JSON

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 : int

The un-normalized index of the axis. Can be negative

ndim : int

The number of dimensions of the array that axis should be normalized against

msg_prefix : str

A prefix to put before the message, typically the name of the argument

Returns

normalized_axis : int

The normalized axis index, such that 0 <= normalized_axis < ndim

Raises

: AxisError

If the axis index is invalid, when -ndim <= axis < ndim is 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