What is a view?
A view is an array that shares its underlying data buffer with another array. When you create a view, no data is copied — the new array simply references the same memory with different shape, strides, or offset metadata. Modifying elements through a view changes the original array, and vice versa.
A copy is an independent array with its own data buffer. Changes to a copy never affect the original.
Operations that return views
These operations return arrays that share data with the input. No memory is allocated for array elements.
reshape and ravel return views only when the source array is C-contiguous. If the array is not contiguous in memory (for example, after a transpose), these operations must allocate a copy.
Operations that return copies
These operations always allocate a new data buffer.
Detecting views: base and flags
The base property
Every view has a base property pointing to the array that owns the data. Arrays that own their data return null.
The flags property
The flags object exposes three boolean flags:
View mutation affects the original
This is the most important consequence of views. Changing a value through any view changes the underlying data for every array that references it.
Contiguity and reshape
An array is C-contiguous when its elements are stored in row-major order with no gaps. Most freshly created arrays are C-contiguous. However, operations like transpose change the stride pattern without moving data, producing arrays that are no longer C-contiguous.
This matters because reshape can only return a view when the data is already in the right memory order:
If you need to ensure an array is contiguous before reshaping (to guarantee a view), use ascontiguousarray first.
Explicit copies
When you need an independent copy, use copy:
Or use the method form on NDArray:
If you pass an array to a function and want to prevent the function from modifying your data, pass copy(arr) instead. numpy-ts follows NumPy’s convention: slicing returns views, not copies.
Summary