numpy.ma.apply_over_axes
-
numpy.ma.apply_over_axes(func, a, axes)
[source] -
Apply a function repeatedly over multiple axes.
func
is called asres = func(a, axis)
, whereaxis
is the first element ofaxes
. The resultres
of the function call must have either the same dimensions asa
or one less dimension. Ifres
has one less dimension thana
, a dimension is inserted beforeaxis
. The call tofunc
is then repeated for each axis inaxes
, withres
as the first argument.- Parameters
-
-
funcfunction
-
This function must take two arguments,
func(a, axis)
. -
aarray_like
-
Input array.
-
axesarray_like
-
Axes over which
func
is applied; the elements must be integers.
-
- Returns
-
-
apply_over_axisndarray
-
The output array. The number of dimensions is the same as
a
, but the shape can be different. This depends on whetherfunc
changes the shape of its output with respect to its input.
-
See also
-
apply_along_axis
-
Apply a function to 1-D slices of an array along the given axis.
Examples
>>> a = np.ma.arange(24).reshape(2,3,4) >>> a[:,0,1] = np.ma.masked >>> a[:,1,:] = np.ma.masked >>> a masked_array( data=[[[0, --, 2, 3], [--, --, --, --], [8, 9, 10, 11]], [[12, --, 14, 15], [--, --, --, --], [20, 21, 22, 23]]], mask=[[[False, True, False, False], [ True, True, True, True], [False, False, False, False]], [[False, True, False, False], [ True, True, True, True], [False, False, False, False]]], fill_value=999999) >>> np.ma.apply_over_axes(np.ma.sum, a, [0,2]) masked_array( data=[[[46], [--], [124]]], mask=[[[False], [ True], [False]]], fill_value=999999)
Tuple axis arguments to ufuncs are equivalent:
>>> np.ma.sum(a, axis=(0,2)).reshape((1,-1,1)) masked_array( data=[[[46], [--], [124]]], mask=[[[False], [ True], [False]]], fill_value=999999)
© 2005–2020 NumPy Developers
Licensed under the 3-clause BSD License.
https://numpy.org/doc/1.19/reference/generated/numpy.ma.apply_over_axes.html