numpoly.apply_over_axes

numpoly.apply_over_axes(func: Callable, a: numpoly.typing.PolyLike, axes: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]])numpoly.baseclass.ndpoly[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.

Args:
func:

This function must take two arguments, func(a, axis).

a:

Input array.

axes:

Axes over which func is applied; the elements must be integers.

Return:

The output array. 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.

Example:
>>> polynomial = numpy.arange(24).reshape(2, 4, 3)
>>> polynomial = polynomial*numpoly.variable(3)
>>> numpoly.apply_over_axes(
...     func=numpoly.sum, a=polynomial, axes=1)
polynomial([[[18*q0, 22*q1, 26*q2]],

            [[66*q0, 70*q1, 74*q2]]])
>>> numpoly.apply_over_axes(
...     func=numpoly.sum, a=polynomial, axes=[0, 2])
polynomial([[[16*q2+14*q1+12*q0],
             [22*q2+20*q1+18*q0],
             [28*q2+26*q1+24*q0],
             [34*q2+32*q1+30*q0]]])