I am not sure how I feel about this. If I understand correctly, the issue started as a corner case when the indices were incorrect, and grew to dealing with initial values, and then added a desire for piecewise reducat with multiple segements. Is that correct? Could you give a better summary of the issue the PR is trying to solve? The examples look magic to me, it took me a long time to understand that the `[1, 3, 5]` correspond to start indices and `[2, -1, 0]` correspond to stop indices. Perhaps we should require kwarg use instead of positional to make the code more readable. Matti On Sun, Nov 24, 2024 at 3:13 AM Marten van Kerkwijk <mhvk@astro.utoronto.ca> wrote:
Hi All,
This discussion about updating reduceat went silent, but recently I came back to my PR to allow `indices` to be a 2-dimensional array of start and stop values (or a tuple of separate start and stop arrays). I thought a bit more about it and think it is the easiest way to extend the present definition. So, I have added some tests and documentation and would now like to open it for proper discussion. See
https://github.com/numpy/numpy/pull/25476
From the examples there:
a = np.arange(12) np.add.reduceat(a, ([1, 3, 5], [2, -1, 0])) # array([ 1, 52, 0]) np.minimum.reduceat(a, ([1, 3, 5], [2, -1, 0]), initial=10) # array([ 1, 3, 10]) np.minimum.reduceat(a, ([1, 3, 5], [2, -1, 0])) # ValueError: empty slice encountered with reduceat operation for 'minimum', which does not have an identity. Specify 'initial'.Let me know what you all think,
Marten
p.s. Rereading the thread, I see we discussed initial vs default values in some detail. This is interesting, but somewhat orthogonal to the PR, since it just copies behaviour already present for reduce. _______________________________________________ NumPy-Discussion mailing list -- numpy-discussion@python.org To unsubscribe send an email to numpy-discussion-leave@python.org https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ Member address: matti.picus@gmail.com