diff options
author | Marten van Kerkwijk <mhvk@astro.utoronto.ca> | 2017-02-21 15:58:08 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-21 15:58:08 -0500 |
commit | 2aabeafb97bea4e1bfa29d946fbf31e1104e7ae0 (patch) | |
tree | 2cd08a2211a3ec1f7403c17dd175aca73a93bccb /numpy/add_newdocs.py | |
parent | 070b9660282288fa8bb376533667f31613373337 (diff) | |
parent | 8d6ec65c925ebef5e0567708de1d16df39077c9d (diff) | |
download | numpy-2aabeafb97bea4e1bfa29d946fbf31e1104e7ae0.tar.gz |
Merge pull request #8584 from eric-wieser/resolve_axis
MAINT: Use the same exception for all bad axis requests
Diffstat (limited to 'numpy/add_newdocs.py')
-rw-r--r-- | numpy/add_newdocs.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py index 09f4e40c4..3916d1304 100644 --- a/numpy/add_newdocs.py +++ b/numpy/add_newdocs.py @@ -6728,6 +6728,51 @@ add_newdoc('numpy.core.multiarray', 'busday_count', 53 """) +add_newdoc('numpy.core.multiarray', 'normalize_axis_index', + """ + normalize_axis_index(axis, ndim) + + 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. + + Used internally by all axis-checking logic. + + .. versionadded:: 1.13.0 + + 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 + + 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 + -------- + >>> normalize_axis_index(0, ndim=3) + 0 + >>> normalize_axis_index(1, ndim=3) + 1 + >>> normalize_axis_index(-1, ndim=3) + 2 + + >>> normalize_axis_index(3, ndim=3) + Traceback (most recent call last): + ... + AxisError: axis 3 is out of bounds for array of dimension 3 + """) + ############################################################################## # # nd_grid instances |