diff options
Diffstat (limited to 'numpy/lib/shape_base.py')
-rw-r--r-- | numpy/lib/shape_base.py | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py index de8606167..e81bae5fc 100644 --- a/numpy/lib/shape_base.py +++ b/numpy/lib/shape_base.py @@ -55,14 +55,11 @@ def apply_along_axis(func1d,axis,arr,*args): For a function that doesn't return a scalar, the number of dimensions in `outarr` is the same as `arr`. - >>> def new_func(a): - ... \"\"\"Divide elements of a by 2.\"\"\" - ... return a * 0.5 - >>> b = np.array([[1,2,3], [4,5,6], [7,8,9]]) - >>> np.apply_along_axis(new_func, 0, b) - array([[ 0.5, 1. , 1.5], - [ 2. , 2.5, 3. ], - [ 3.5, 4. , 4.5]]) + >>> b = np.array([[8,1,7], [4,3,9], [5,2,6]]) + >>> np.apply_along_axis(sorted, 1, b) + array([[1, 7, 8], + [3, 4, 9], + [2, 5, 6]]) """ arr = asarray(arr) @@ -643,10 +640,9 @@ def get_array_prepare(*args): In case of ties, leftmost wins. If no wrapper is found, return None """ - wrappers = [(getattr(x, '__array_priority__', 0), -i, + wrappers = sorted((getattr(x, '__array_priority__', 0), -i, x.__array_prepare__) for i, x in enumerate(args) - if hasattr(x, '__array_prepare__')] - wrappers.sort() + if hasattr(x, '__array_prepare__')) if wrappers: return wrappers[-1][-1] return None @@ -656,10 +652,9 @@ def get_array_wrap(*args): In case of ties, leftmost wins. If no wrapper is found, return None """ - wrappers = [(getattr(x, '__array_priority__', 0), -i, + wrappers = sorted((getattr(x, '__array_priority__', 0), -i, x.__array_wrap__) for i, x in enumerate(args) - if hasattr(x, '__array_wrap__')] - wrappers.sort() + if hasattr(x, '__array_wrap__')) if wrappers: return wrappers[-1][-1] return None |