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

How to use Python cumsums and cumprod functions

高洛峰
Release: 2017-03-21 11:45:21
Original
5581 people have browsed it

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]])
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template