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/lib/shape_base.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/lib/shape_base.py')
-rw-r--r-- | numpy/lib/shape_base.py | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py index 58e13533b..62798286f 100644 --- a/numpy/lib/shape_base.py +++ b/numpy/lib/shape_base.py @@ -7,6 +7,7 @@ from numpy.core.numeric import ( asarray, zeros, outer, concatenate, isscalar, array, asanyarray ) from numpy.core.fromnumeric import product, reshape, transpose +from numpy.core.multiarray import normalize_axis_index from numpy.core import vstack, atleast_3d from numpy.lib.index_tricks import ndindex from numpy.matrixlib.defmatrix import matrix # this raises all the right alarm bells @@ -96,10 +97,7 @@ def apply_along_axis(func1d, axis, arr, *args, **kwargs): # handle negative axes arr = asanyarray(arr) nd = arr.ndim - if not (-nd <= axis < nd): - raise IndexError('axis {0} out of bounds [-{1}, {1})'.format(axis, nd)) - if axis < 0: - axis += nd + axis = normalize_axis_index(axis, nd) # arr, with the iteration axis at the end in_dims = list(range(nd)) @@ -289,8 +287,7 @@ def expand_dims(a, axis): """ a = asarray(a) shape = a.shape - if axis < 0: - axis = axis + len(shape) + 1 + axis = normalize_axis_index(axis, a.ndim + 1) return a.reshape(shape[:axis] + (1,) + shape[axis:]) row_stack = vstack |