Python| numpy matrix.cumsum()
在Numpy matrix.cumsum()
方法的帮助下,我们能够找到给定矩阵的cumulative sum
,并将输出作为一维矩阵。
Syntax : matrix.cumsum()
Return : Return cumulative sum of matrix
示例 #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]]