[Numpy-discussion] Fixing inconsistent behaviour of reduceat()

Dive Nex divenex at gmail.com
Thu Apr 13 07:02:33 EDT 2017


Hi all,


I would like to try to reach a consensus about a long standing inconsistent
behavior of reduceat() reported and discussed here


  https://github.com/numpy/numpy/issues/834


In summary, it seems an elegant and logical design choice, that all users
will expect, for


    out = ufunc.reduceat(a, indices)


to produce, for all indices j (except for the last one) the following


    out[j] = ufunc.reduce(a[indices[j]:indices[j+1]])


However the current documented and actual behavior is for the case


    indices[i] >= indices[i+1]

to return simply


    out[j] = a[indices[i]]


I cannot see any application where this behavior is useful or where this
choice makes sense. This seems just a bug that should be fixed.


What do people think?


PS: A quick fix for the current implementation is


    out = ufunc.reduceat(a, indices)
    out *= np.diff(indices) > 0
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20170413/8c8d4a7a/attachment.html>


More information about the NumPy-Discussion mailing list