May 2019
Beginner
528 pages
29h 51m
English
Though views are separate array objects, they save memory by sharing element data from other arrays. However, when sharing mutable values, sometimes it’s necessary to create a deep copy with independent copies of the original data. This is especially important in multi-core programming, where separate parts of your program could attempt to modify your data at the same time, possibly corrupting it.
The array method copy returns a new array object with a deep copy of the original array object’s data. First, let’s create an array and a deep copy of that array:
In [1]: import numpy as npIn [2]: numbers = np.arange(1, 6)In [3]: numbersOut[3]: array([1, 2, 3, 4, 5])In [4]: numbers2 = numbers.copy()In [5]: numbers2Out[5]: array([1, ...
Read now
Unlock full access