Home  >  Article  >  Backend Development  >  How to use Python cumsums and cumprod functions

How to use Python cumsums and cumprod functions

高洛峰
高洛峰Original
2017-03-21 11:45:215572browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn