Home > Article > Backend Development > How to use Python cumsums and cumprod functions
This article explains in detail how to use the Python cumsums and cumprod functions
>>>a = np.array([1,2,3],[4,5,6]]) >>>a array([[1,2,3], [4,5,6]]) >>>a.cumsum(0) array([[1,2,3], [5,7,9]]) >>>a.cumprod(1) array([[1,2,6], [4,20,120]])
The difficulty in these two functions is that the parameters 0 and 1
where 0 represents the column Calculation, 1 represents the calculation of rows, that is, the cumulative sum and product of columns and rows respectively.
And the result is not aggregated, and an intermediate array is produced.
The above is the detailed content of How to use Python cumsums and cumprod functions. For more information, please follow other related articles on the PHP Chinese website!