bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / apply_over_axes
_ArrayFunctionDispatcher
numpy:apply_over_axes
source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/lib/_shape_base_impl.py :423
Signature
def apply_over_axes ( func , a , axes ) Summary
Apply a function repeatedly over multiple axes.
Extended Summary
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
func: functionThis function must take two arguments,
func(a, axis).a: array_likeInput array.
axes: array_likeAxes over which
funcis applied; the elements must be integers.
Returns
apply_over_axis: ndarrayThe output array. The number of dimensions is the same as
a, but the shape can be different. This depends on whetherfuncchanges the shape of its output with respect to its input.
Notes
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.
Examples
import numpy as np a = np.arange(24).reshape(2,3,4)✓
a
✗np.apply_over_axes(np.sum, a, [0,2])
✓np.sum(a, axis=(0,2), keepdims=True)
✓See also
- apply_along_axis
Apply a function to 1-D slices of an array along the given axis.
Aliases
-
numpy.apply_over_axes