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 computes ufunc.reduce(a[indices[i]:indices[i+1]]), which becomes the i-th generalized “row” parallel to axis in the final result (i.e., in a 2-D array, for example, if axis = 0, it becomes the i-th row, but if axis = 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 simply a[in