Views and Copies
This lesson discusses views and copies, and their uses in NumPy. We'll also find out the difference between indexing and fancy indexing and between ravel and flatten and how and why we make temporary copy.
We'll cover the following
Views and copies are important concepts for the optimization of your numerical computations. Even if we’ve already manipulated them in the previous section, the whole story is a bit more complex.
Direct and indirect access
While executing a numpy instruction, either a copy of the input array is created or a view is provided. When the contents are physically stored in another location, it is called Copy. If on the other hand, a different view of the same memory content is provided, we call it View.
Indexing and Fancy Indexing
First, we have to distinguish between indexing and fancy indexing. The first will always return a view while the second will return a copy. This difference is important because in the first case, modifying the view modifies the base array while this is not true in the second case: