Running maximum of numpy array values

前端 未结 2 2004
被撕碎了的回忆
被撕碎了的回忆 2020-12-03 20:46

I need a fast way to keep a running maximum of a numpy array. For example, if my array was:

x = numpy.array([11,12,13,20,19,18,17,18,23,21])
<
相关标签:
2条回答
  • 2020-12-03 21:17

    As suggested, there is scipy.maximum.accumulate:

    In [9]: x
    Out[9]: [1, 3, 2, 5, 4]
    
    In [10]: scipy.maximum.accumulate(x)
    Out[10]: array([1, 3, 3, 5, 5])
    
    0 讨论(0)
  • 2020-12-03 21:22

    numpy.maximum.accumulate works for me.

    >>> import numpy
    >>> numpy.maximum.accumulate(numpy.array([11,12,13,20,19,18,17,18,23,21]))
    array([11, 12, 13, 20, 20, 20, 20, 20, 23, 23])
    
    0 讨论(0)
提交回复
热议问题