General#

ivy.reduce(operand, init_value, computation, /, *, axes=0, keepdims=False)[source]#

Reduces the input array’s dimensions by applying a function along one or more axes.

Parameters:
  • operand (Union[Array, NativeArray]) – The array to act on.

  • init_value (Union[int, float]) – The value with which to start the reduction.

  • computation (Callable) – The reduction function.

  • axes (Union[int, Sequence[int]], default: 0) – The dimensions along which the reduction is performed.

  • keepdims (bool, default: False) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one.

Return type:

Array

Returns:

ret – The reduced array.

Examples

>>> x = ivy.array([[1, 2, 3], [4, 5, 6]])
>>> ivy.reduce(x, 0, ivy.add, 0)
ivy.array([6, 15])
>>> x = ivy.array([[1, 2, 3], [4, 5, 6]])
>>> ivy.reduce(x, 0, ivy.add, 1)
ivy.array([5, 7, 9])

This should have hopefully given you an overview of the general submodule, if you have any questions, please feel free to reach out on our discord!