Python | Numpy matrix.cumprod ()



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

Syntax: matrix.cumprod()

Return: Return cumulative product of matrix

Example # 1:
In this example, we see that using the matrix.cumprod ( ) we can find the cumulative product of a given matrix.

# import important module into python

import numpy as np

 
# make a matrix with NumPy

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

 
# using the matrix.cumprod () method

geeks = gfg.cumprod ()

 

print (geeks)

Exit:

 [[6 12 36]] 

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] ` )

  
# applying the matrix.cumprod () method

geeks = gfg.cumprod ()

 

print (geeks)

Exit:

 [[1 2 6 24 120 720]]