Python | Numpy matrix.setfield ()

Using the matrix.setfield() method, all matrix fields are set to a value that is passed as a parameter.

Syntax: matrix.setfield()

Return: new matrix having the value passed as parameter

Example # 1:

In this example we see that matrix.setfield () is used to generate a new matrix, the value of which is passed to as a parameter in this method.

# import an important module in python

import numpy as np

 
# make a matrix with NumPy

gfg = np.matrix ( `[4, 1; 12, 3] ` )

  
# using the matrix.setfield () method

gfg.setfield ( 2 , np.int32)

 

print (gfg)

Exit:

 [[2 2] [2 2]] 

Example # 2:

# import an important module into python

import numpy as np

 
# make a matrix with NumPy

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

  
# applying the matrix.setfield () method

gfg.setfield ( 25 , np.int32)

 

print (gfg)

Exit:

 [[25 25 25] [25 25 25] [25 25 25]]