Python | Numpy matrix.cumsum ()

NumPy | Python Methods and Functions

Using the Numpy matrix.cumsum () method, we can find the cumulative sum of a given matrix and output it as a one-dimensional matrix.

Syntax: matrix.cumsum()

Return: Return cumulative sum of matrix

Example # 1:
In this example, we see that using the matrix.cumsum ( ) we can find the cumulative sum of the given array.

# import important module into python

import numpy as np

 
# make a matrix with NumPy

gfg = np.matrix ( `[6, 2 , 3] ` )

  
# using the matrix.cumsum () method

geeks = gfg.cumsum ()

 

print (geeks)

Output:

 [[6 8 11]] 

Example # 2:

# import important module in python

import numpy as np

 
# make a matrix with NumPy

gfg = np.matrix ( ` [1, 2, 3; 4, 5, 6] ` )

  
# using the matrix.cumsum () method

geeks = gfg.cumsum ()

 

print (geeks)

Exit:

 [[1 3 6 10 15 21]] 




Get Solution for free from DataCamp guru