[Numpy-discussion] Questionable reduceat behavior

Wes McKinney wesmckinn@gmail....
Sun Aug 14 10:58:30 CDT 2011


On Sat, Aug 13, 2011 at 8:06 PM, Mark Wiebe <mwwiebe@gmail.com> wrote:
> Looks like this is the second-oldest open bug in the bug tracker.
> http://projects.scipy.org/numpy/ticket/236
> For what it's worth, I'm in favour of changing this behavior to be more
> consistent as proposed in that ticket.
> -Mark
>
> On Thu, Aug 11, 2011 at 11:25 AM, Wes McKinney <wesmckinn@gmail.com> wrote:
>>
>> 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?
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>

Well, I certainly hope it doesn't get forgotten about for another 5
years. I think having more consistent behavior would be better rather
than conforming to a seemingly arbitrary decision made ages ago in
Numeric.

- Wes


More information about the NumPy-Discussion mailing list