📜  Python| numpy matrix.cumsum()

📅  最后修改于: 2022-05-13 01:55:46.684000             🧑  作者: Mango

Python| numpy matrix.cumsum()

Numpy matrix.cumsum()方法的帮助下,我们能够找到给定矩阵的cumulative sum ,并将输出作为一维矩阵。

示例 #1:
在这个例子中,我们可以看到在matrix.cumsum()方法的帮助下,我们能够找到给定数组的累积和。

# import the important module in python
import numpy as np
         
# make matrix with numpy
gfg = np.matrix('[6, 2, 3]')
         
# applying matrix.cumsum() method
geeks = gfg.cumsum()
   
print(geeks)
输出:
[[ 6  8 11]]

示例 #2:

# import the important module in python
import numpy as np
         
# make a matrix with numpy
gfg = np.matrix('[1, 2, 3; 4, 5, 6]')
         
# applying matrix.cumsum() method
geeks = gfg.cumsum()
   
print(geeks)
输出:
[[ 1  3  6 10 15 21]]