NumPy Array Deep Copy

Author: Al-mamun Sarkar Date: 2020-03-31 20:17:30

NumPy Array Deep Copy. The following shows how to create a new copy of a NumPy array of the Python NumPy module. 

import numpy as np

 

In [1]:

a = np.arange(12)
a

Out[1]:

array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11])

 

In [2]:

d = a.copy()
d is a

Out[2]:

False

 

In [3]:

d.base is a

Out[3]:

False

 

In [5]:

d[0,0] = 9999
d

Out[5]:

array([[9999,   10,   10,    3],
       [1234,   10,   10,    7],
       [   8,   10,   10,   11]])

 

In [6]:

a

Out[6]:

array([[   0,   10,   10,    3],
       [1234,   10,   10,    7],
       [   8,   10,   10,   11]])