Calculating cumulative minimum with numpy arrays

前端 未结 2 1937
日久生厌
日久生厌 2021-02-19 11:31

I\'d like to calculate the \"cumulative minimum\" array--basically, the minimum value of an array up to each index such as:

import numpy as np
nums = np.array([5         


        
2条回答
  •  别那么骄傲
    2021-02-19 11:48

    For any 2-argument NumPy universal function, its accumulate method is the cumulative version of that function. Thus, numpy.minimum.accumulate is what you're looking for:

    >>> numpy.minimum.accumulate([5,4,6,10,3])
    array([5, 4, 4, 4, 3])
    

提交回复
热议问题