Python | Numpy matrix.prod ()



Using the Numpy matrix.prod () method, we can get the cumulative product of all elements on one axis from a given matrix.

Syntax: matrix.prod(axis)

Return: Return product from given matrix

Example # 1:
In this example, we see that we can get the product of all elements on one axis from a given matrix using the matrix.prod () method.

# import important module in python

import numpy as np

  
# make a matrix with NumPy

gfg = np.ma trix ( `[64, 1; 12, 3] ` )

  
# using the matrix.prod () method

geeks = gfg.prod ( 1 )

 

print (geeks)

Exit:

 [[64] [36]]  

Example # 2:

# import important module into python

import numpy as np

 
# make a matrix with NumPy

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

  
# using the matrix.prod () method

geeks = gfg.prod ( 0 )

 

print (geeks)

Exit:

 [[28 80 -162]]