mindspore.numpy.apply_over_axes

View Source On Gitee
mindspore.numpy.apply_over_axes(func, a, axes)[source]

Applies 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
  • func (function) – This function must take two arguments, func(a, axis).

  • a (Union[int, float, bool, list, tuple, Tensor]) – Input tensor.

  • axes (Union[int, list, tuple]) – Axes over which func is applied; the elements must be integers.

Returns

Tensor. The number of dimensions is the same as a, but the shape can be different. This depends on whether func changes the shape of its output with respect to its input.

Raises
  • TypeError – If input a is not array_like or axes is not int or sequence of ints.

  • ValueError – If any axis is out of range or duplicate axes exist.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore.numpy as np
>>> x = np.arange(10).reshape(2, 5).astype('float32')
>>> print(x)
[[0. 1. 2. 3. 4.]
 [5. 6. 7. 8. 9.]]
>>> print(np.apply_over_axes(np.sum, x, axes=0))
[[ 5.  7.  9. 11. 13.]]