Python | numpy.copyto () function

NumPy | Python Methods and Functions

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

Syntax: numpy.copyto (destination, source)

Return: Return copy of an array

Example # 1:
In this example, we can see that using the numpy.copyto () method we create a copy of the element in the target array.

# import important module in python

import numpy as np

 
# make an array with NumPy

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

geeks = [ 4 , 5 , 6 ]

  
# using the numpy.copyto () method
np.copyto (gfg, geeks)

 

print (gfg)

Exit:

 [4 5 6] 

Example # 2:

# import important module in python

import numpy as np < / code>

 
# make an array with NumPy

gfg = np.array ([[ 1 , 2 , 3 ], [ 4 , 5 , 6 ]] )

geeks = [[ 4 , 5 , 6 ], [ 7 , 8 , 9 ]]

  
# using the numpy.copyto () method
np.copyto (gfg, geeks)

 

print (gfg)

Exit:

 [[4 5 6] [7 8 9]] 




Get Solution for free from DataCamp guru