Charles R Harris
Wed Sep 23 10:07:37 CDT 2009
On Wed, Sep 23, 2009 at 8:34 AM, Nissim Karpenstein <email@example.com>wrote:
> 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
> 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 : a = arange(10)
In : a[5:] = 0
In : maximum.accumulate(a)
Out: array([0, 1, 2, 3, 4, 4, 4, 4, 4, 4])
PyArray_Max is there because it is an ndarray method.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion