Python | Numpy matrix.copy ()



Using the Numpy matrix.copy () method, we can make a copy of all data items present in the matrix. If we change any data item in the copy, it will not affect the original matrix.

Syntax: matrix.copy ()

Return: Return copy of matrix

Example # 1:
In this example, we can see that using the matrix.copy () method we are making a copy of the element in another matrix.

# import an important module into python

import numpy as np

 
# make a matrix with NumPy

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

  
# using the matrix.copy () method

geeks = gfg.copy ()

 

print (geeks)

Exit:

 [[1 2 3]] 

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.copy () method

geeks = gfg.copy ()

 

print (geeks)

Exit:

 [[1 2 3] [4 5 6]]