Python | Numpy matrix.fill ()

Using the Numpy matrix.fill () method, we can fill in the scalar value in a given matrix and output it as a matrix having scalar values.

Syntax: matrix.fill(value)

Return: Return a matrix having scalar value

Example # 1:
In this example, we see that using the matrix.fill () we can fill the given matrix with a scalar value.

# import important module in python

import numpy as np

 
# make a matrix with NumPy

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

 
# using the matrix.fill () method

gfg.fill ( 0 )

 

print (gfg)

Exit:

 [[0 0 0]] 

Example # 2:

# import an important module into python

import numpy as np

 
# make a matrix with NumPy

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

  
# applying the matrix.fill () method

gfg.fill ( 1 )

 

print (gfg)

Exit:

 [[1 1 1] [1 1 1]]