October 2019
Beginner to intermediate
674 pages
16h 43m
English
A view on a NumPy array is just a particular way of portraying the data it contains. Creating a view does not result in a new copy of the array, rather the data it contains may be arranged in a specific order, or only certain data rows may be shown. Thus, if data is replaced on the underlying array's data, this will be reflected in the view whenever the data is accessed via indexing.
The initial array is not copied into the memory during slicing and is thus more efficient. The np.may_share_memory method can be used to see whether two arrays share the same memory block. However, it should be used with caution as it may produce false positives. Modifying a view modifies the original array:
In [118]:ar1=np.arange(12); ar1 Out[118]:array([ ...
Read now
Unlock full access