[Numpy-discussion] Questionable reduceat behavior
Mark Wiebe
mwwiebe@gmail....
Sat Aug 13 19:06:59 CDT 2011
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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110813/f4481931/attachment.html
More information about the NumPy-Discussion
mailing list