Python | Numpy ndarray .__ copy __ ()

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

Syntax: numpy.__copy__()

Return: Copy of all the data elements

Example # 1:
In this example, we can see that using the numpy .__ copy__ method () we make a copy of the element.

# import an important module into python

import numpy as np

 
# make an array with NumPy

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

 
# applying the ndarray method .__ copy __ ()

geeks = gfg .__ copy __ ()

 

print (geeks)

Exit:

 [1 2 3 4 5] 

Example # 2:

# import important module into python

import numpy as np

 
# make an array with NumPy

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

[ 6 , 5 , 4 , 3 , 2 ]])

 
# applying the ndarray method .__ copy __ ()

geeks = gfg .__ copy __ ()

  # Modify data item

geeks [ 0 ] [ 2 ] = 10

 

print (gfg, end = `` )

print (geeks)

Exit:

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