numpy.apply_over_axes(func, a, axes)
[source]
Apply a function repeatedly over multiple axes.
func
is called as res = func(a, axis)
, where axis
is the first element of axes
. The result res
of the function call must have either the same dimensions as a
or one less dimension. If res
has one less dimension than a
, a dimension is inserted before axis
. The call to func
is then repeated for each axis in axes
, with res
as the first argument.
Parameters: |
|
---|---|
Returns: |
|
See also
apply_along_axis
This function is equivalent to tuple axis arguments to reorderable ufuncs with keepdims=True. Tuple axis arguments to ufuncs have been available since version 1.7.0.
>>> a = np.arange(24).reshape(2,3,4) >>> a array([[[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]], [[12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23]]])
Sum over axes 0 and 2. The result has same number of dimensions as the original array:
>>> np.apply_over_axes(np.sum, a, [0,2]) array([[[ 60], [ 92], [124]]])
Tuple axis arguments to ufuncs are equivalent:
>>> np.sum(a, axis=(0,2), keepdims=True) array([[[ 60], [ 92], [124]]])
© 2005–2019 NumPy Developers
Licensed under the 3-clause BSD License.
https://docs.scipy.org/doc/numpy-1.17.0/reference/generated/numpy.apply_over_axes.html