### Navigation

- index
- modules |
- modules |
- next |
- previous |
- NumPy v1.5 Manual (DRAFT) »
- NumPy Reference »
- Universal functions (`ufunc`) »

# numpy.ufunc.reduce

`ufunc.``reduce`(a, axis=0, dtype=None, out=None)

  Reduces a‘s dimension by one, by applying ufunc along one axis.

  Let . Then = the result of iterating j over , cumulatively applying ufunc to each . For a one-dimensional array, reduce produces results equivalent to:

      r = op.identity # op = ufunc
      for i in xrange(len(A)):
        r = op(r, A[i])
      return r

  For example, add.reduce() is equivalent to sum().

  Parameters : | a : array_like The array to act on. axis : int, optional The axis along which to apply the reduction. dtype : data-type code, optional The type used to represent the intermediate results. Defaults to the data-type of the output array if this is provided, or the data-type of the input array if no output array is provided. out : ndarray, optional A location into which the result is stored. If not provided, a freshly-allocated array is returned.
  Returns : | r : ndarray The reduced array. If out was supplied, r is a reference to it.

  Examples

      >>> np.multiply.reduce([2,3,5])
      30

  A multi-dimensional array example:

      >>> X = np.arange(8).reshape((2,2,2))
      >>> X
      array([[[0, 1],
              [2, 3]],
             [[4, 5],
              [6, 7]]])
      >>> np.add.reduce(X, 0)
      array([[ 4,  6],
             [ 8, 10]])
      >>> np.add.reduce(X) # confirm: default axis value is 0
      array([[ 4,  6],
             [ 8, 10]])
      >>> np.add.reduce(X, 1)
      array([[ 2,  4],
             [10, 12]])
      >>> np.add.reduce(X, 2)
      array([[ 1,  5],
             [ 9, 13]])

### Navigation

- index
- modules |
- modules |
- next |
- previous |
- NumPy v1.5 Manual (DRAFT) »
- NumPy Reference »
- Universal functions (`ufunc`) »