"Reduce" is a general concept, and I found a decent definition at https://docs.python.org/3/library/functools.html#functools.reduce
Apply function of two arguments cumulatively to the items of sequence, from left to right, so as to reduce the sequence to a single value.
Numpy's ufunc reduce is documented at https://docs.scipy.org/doc/numpy/reference/generated/numpy.ufunc.reduce.html
Reduces a’s dimension by one, by applying ufunc along one axis.
So np.add.reduce(a)
(also known as np.add.reduce(a, axis=0)
) will call np.add
on a[0]
and a[1]
, then add the result to a[2]
, etc. until it incorporates all len(a)
elements.
Result: array([5, 7, 9])
np.add(x, y)
is basically x + y
. np.add.reduce(a, axis=0)
is basically np.sum(a, axis=0)
.
np.add.reduce(a, axis=1)
adds a[:, 0]
to a[:, 1]
, then adds result to a[:, 2]
, and so on.`
Result: array([ 6, 15])