summaryrefslogtreecommitdiff
path: root/numpy/lib/shape_base.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/lib/shape_base.py')
-rw-r--r--numpy/lib/shape_base.py32
1 files changed, 23 insertions, 9 deletions
diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py
index 4fdaba349..a6d391728 100644
--- a/numpy/lib/shape_base.py
+++ b/numpy/lib/shape_base.py
@@ -12,7 +12,7 @@ from numpy.core.numeric import asarray, zeros, newaxis, outer, \
from numpy.core.fromnumeric import product, reshape
from numpy.core import hstack, vstack, atleast_3d
-def apply_along_axis(func1d,axis,arr,*args):
+def apply_along_axis(func1d, axis, arr, *args, **kwargs):
"""
Apply a function to 1-D slices along the given axis.
@@ -30,6 +30,11 @@ def apply_along_axis(func1d,axis,arr,*args):
Input array.
args : any
Additional arguments to `func1d`.
+ kwargs: any
+ Additional named arguments to `func1d`.
+
+ .. versionadded:: 1.9.0
+
Returns
-------
@@ -78,7 +83,7 @@ def apply_along_axis(func1d,axis,arr,*args):
i[axis] = slice(None, None)
outshape = asarray(arr.shape).take(indlist)
i.put(indlist, ind)
- res = func1d(arr[tuple(i.tolist())],*args)
+ res = func1d(arr[tuple(i.tolist())], *args, **kwargs)
# if res is a number, then we have a smaller output array
if isscalar(res):
outarr = zeros(outshape, asarray(res).dtype)
@@ -94,7 +99,7 @@ def apply_along_axis(func1d,axis,arr,*args):
ind[n] = 0
n -= 1
i.put(indlist, ind)
- res = func1d(arr[tuple(i.tolist())],*args)
+ res = func1d(arr[tuple(i.tolist())], *args, **kwargs)
outarr[tuple(ind)] = res
k += 1
return outarr
@@ -115,7 +120,7 @@ def apply_along_axis(func1d,axis,arr,*args):
ind[n] = 0
n -= 1
i.put(indlist, ind)
- res = func1d(arr[tuple(i.tolist())],*args)
+ res = func1d(arr[tuple(i.tolist())], *args, **kwargs)
outarr[tuple(i.tolist())] = res
k += 1
return outarr
@@ -153,6 +158,12 @@ def apply_over_axes(func, a, axes):
apply_along_axis :
Apply a function to 1-D slices of an array along the given axis.
+ Notes
+ ------
+ This function is equivalent to tuple axis arguments to reorderable ufuncs
+ with keepdims=True. Tuple axis arguments to ufuncs have been availabe since
+ version 1.7.0.
+
Examples
--------
>>> a = np.arange(24).reshape(2,3,4)
@@ -172,6 +183,13 @@ def apply_over_axes(func, a, axes):
[ 92],
[124]]])
+ Tuple axis arguments to ufuncs are equivalent:
+
+ >>> np.sum(a, axis=(0,2), keepdims=True)
+ array([[[ 60],
+ [ 92],
+ [124]]])
+
"""
val = asarray(a)
N = a.ndim
@@ -274,10 +292,6 @@ def column_stack(tup):
--------
hstack, vstack, concatenate
- Notes
- -----
- This function is equivalent to ``np.vstack(tup).T``.
-
Examples
--------
>>> a = np.array((1,2,3))
@@ -638,7 +652,7 @@ def dsplit(ary, indices_or_sections):
"""
if len(_nx.shape(ary)) < 3:
- raise ValueError('vsplit only works on arrays of 3 or more dimensions')
+ raise ValueError('dsplit only works on arrays of 3 or more dimensions')
return split(ary, indices_or_sections, 2)
def get_array_prepare(*args):