ufunc.reduceat()
numpy.ufunc.reduceat
-
ufunc.reduceat(a, indices, axis=0, dtype=None, out=None)
-
Performs a (local) reduce with specified slices over a single axis.
For i in
range(len(indices))
,reduceat
computesufunc.reduce(a[indices[i]:indices[i+1]])
, which becomes the i-th generalized “row” parallel toaxis
in the final result (i.e., in a 2-D array, for example, ifaxis = 0
, it becomes the i-th row, but ifaxis = 1
, it becomes the i-th column). There are three exceptions to this:- when
i = len(indices) - 1
(so for the last index),indices[i+1] = a.shape[axis]
. - if
indices[i] >= indices[i + 1]
, the i-th generalized “row” is simplya[in
- when