12
12
from numpy .core .fromnumeric import product , reshape
13
13
from numpy .core import hstack , vstack , atleast_3d
14
14
15
- def apply_along_axis (func1d ,axis ,arr ,* args ):
15
+ def apply_along_axis (func1d , axis , arr , * args , ** kwargs ):
16
16
"""
17
17
Apply a function to 1-D slices along the given axis.
18
18
@@ -30,6 +30,11 @@ def apply_along_axis(func1d,axis,arr,*args):
30
30
Input array.
31
31
args : any
32
32
Additional arguments to `func1d`.
33
+ kwargs: any
34
+ Additional named arguments to `func1d`.
35
+
36
+ .. versionadded:: 1.9.0
37
+
33
38
34
39
Returns
35
40
-------
@@ -78,7 +83,7 @@ def apply_along_axis(func1d,axis,arr,*args):
78
83
i [axis ] = slice (None , None )
79
84
outshape = asarray (arr .shape ).take (indlist )
80
85
i .put (indlist , ind )
81
- res = func1d (arr [tuple (i .tolist ())],* args )
86
+ res = func1d (arr [tuple (i .tolist ())], * args , ** kwargs )
82
87
# if res is a number, then we have a smaller output array
83
88
if isscalar (res ):
84
89
outarr = zeros (outshape , asarray (res ).dtype )
@@ -94,7 +99,7 @@ def apply_along_axis(func1d,axis,arr,*args):
94
99
ind [n ] = 0
95
100
n -= 1
96
101
i .put (indlist , ind )
97
- res = func1d (arr [tuple (i .tolist ())],* args )
102
+ res = func1d (arr [tuple (i .tolist ())], * args , ** kwargs )
98
103
outarr [tuple (ind )] = res
99
104
k += 1
100
105
return outarr
@@ -115,7 +120,7 @@ def apply_along_axis(func1d,axis,arr,*args):
115
120
ind [n ] = 0
116
121
n -= 1
117
122
i .put (indlist , ind )
118
- res = func1d (arr [tuple (i .tolist ())],* args )
123
+ res = func1d (arr [tuple (i .tolist ())], * args , ** kwargs )
119
124
outarr [tuple (i .tolist ())] = res
120
125
k += 1
121
126
return outarr
0 commit comments