numpy.ma.apply_over_axes

ma.apply_over_axes(func, a, axes)[源代码]

在多个轴上重复应用函数。

func 称为 res = func(a, axis) 在哪里 axis 是的第一个元素 axes . 结果 res 函数调用的维度必须与 a 或者少一个维度。如果 res 尺寸比 a ,在前面插入尺寸 axis . 呼唤 func 然后对中的每个轴重复 axesres 作为第一个论点。

参数
func功能

此函数必须采用两个参数, func(a, axis) .

aarray_like

输入数组。

axesarray_like

轴在哪个轴上 func 应用;元素必须是整数。

返回
apply_over_axis恩达雷

输出数组。尺寸数量与 a 但形状可能不同。这取决于 func 更改其输出相对于其输入的形状。

参见

apply_along_axis

沿给定轴将函数应用于数组的一维切片。

实例

>>> 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)

UFUNC的元组轴参数等效:

>>> np.ma.sum(a, axis=(0,2)).reshape((1,-1,1))
masked_array(
  data=[[[46],
         [--],
         [124]]],
  mask=[[[False],
         [ True],
         [False]]],
  fill_value=999999)