# [Numpy-discussion] Questionable reduceat behavior

Wes McKinney wesmckinn@gmail....
Thu Aug 11 13:25:07 CDT 2011

```I'm a little perplexed why reduceat was made to behave like this:

In [26]: arr = np.ones((10, 4), dtype=bool)

In [27]: arr
Out[27]:
array([[ True,  True,  True,  True],
[ True,  True,  True,  True],
[ True,  True,  True,  True],
[ True,  True,  True,  True],
[ True,  True,  True,  True],
[ True,  True,  True,  True],
[ True,  True,  True,  True],
[ True,  True,  True,  True],
[ True,  True,  True,  True],
[ True,  True,  True,  True]], dtype=bool)

In [30]: np.add.reduceat(arr, [0, 3, 3, 7, 9], axis=0)
Out[30]:
array([[3, 3, 3, 3],
[1, 1, 1, 1],
[4, 4, 4, 4],
[2, 2, 2, 2],
[1, 1, 1, 1]])

this does not seem intuitively correct. Since we have:

In [33]: arr[3:3].sum(0)
Out[33]: array([0, 0, 0, 0])

I would expect

array([[3, 3, 3, 3],
[0, 0, 0, 0],
[4, 4, 4, 4],
[2, 2, 2, 2],
[1, 1, 1, 1]])

Obviously I can RTFM and see why it does this ("if ``indices[i] >=
indices[i + 1]``, the i-th generalized "row" is simply
``a[indices[i]]``"), but it doesn't make much sense to me, and I need
work around it. Suggestions?
```