[Numpy-discussion] cummax

Charles R Harris charlesr.harris@gmail....
Wed Sep 23 10:07:37 CDT 2009


On Wed, Sep 23, 2009 at 8:34 AM, Nissim Karpenstein <nissimk@gmail.com>wrote:

> Hi,
>
> I want a cummax function where given an array inp it returns this:
>
> numpy.array([inp[:i].max() for i in xrange(1,len(inp)+1)]).
>
> Various python versions equivalent to the above are quite slow (though a
> single python loop is much faster than a python loop with a nested numpy C
> loop as shown above).
>
> I have numpy 1.3.0 source.  It looks to me like I could add cummax function
> by simply adding PyArray_CumMax to multiarraymodule.c which would be the
> same as PyArray_Max except it would call PyArray_GenericAccumulateFunction
> instead of PyArray_GenericReduceFunction.  Also add array_cummax to
> arraymethods.c.
>
> Is there interest in adding this function to numpy?  If so, I will check
> out the latest code and try to check in these changes.
> If not, how can I write my own Python module in C that adds this UFunc and
> still gets to reuse the code in PyArray_GenericReduceFunction?
>
>
It's already available

In [5]: a = arange(10)

In [6]: a[5:] = 0

In [7]: maximum.accumulate(a)
Out[7]: array([0, 1, 2, 3, 4, 4, 4, 4, 4, 4])

PyArray_Max is there because it is an ndarray method.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090923/0deb778c/attachment.html 


More information about the NumPy-Discussion mailing list