NumPy copies versus views
Answer: When operating on NumPy arrays, it is possible to access the internal data buffer directly using a view without copying data around. This ensures good performance but can also cause unwanted problems if the user is not aware of how this works. (S1)
Views
- It is possible to access the array differently by just changing certain metadata like stride and dtype without changing the data buffer; these new arrays are called views. (S1)
- The data buffer remains the same, so any changes made to a view reflects in the original copy. (S1)
- A view can be forced through the ndarray.view method. (S1)
- Views are created when elements can be addressed with offsets and strides in the original array. (S1)
Copies
- When a new array is created by duplicating the data buffer as well as the metadata, it is called a copy. (S1)
- Changes made to the copy do not reflect on the original array. (S1)
- Making a copy is slower and memory-consuming but sometimes necessary. (S1)
- The copy method makes a complete copy of the array and its data. (S2)
- Sometimes copy should be called after slicing if the original array is not required anymore. (S2)
No copy at all
- Simple assignments make no copy of objects or their data. (S2)
- Python passes mutable objects as references, so function calls make no copy. (S2)
Claims
- id: C1 claim: Changes made to a view reflect in the original. source: S1 evidence: "to a view reflects in the original copy."
- id: C2 claim: Changes made to a copy do not reflect on the original. source: S1 evidence: "do not reflect on the original array."
- id: C3 claim: Simple assignments make no copy. source: S2 evidence: "Simple assignments make no copy of objects or their data."
- id: C4 claim: The copy method makes a complete copy. source: S2 evidence: "The copy method makes a complete copy of the array and its data."
Sources
- [S1] Copies and views — NumPy v2.5 Manual. NumPy docs. https://numpy.org/doc/stable/user/basics.copies.html . License: BSD-3-Clause (numpy/numpy LICENSE.txt; Copyright (c) 2005-2026, NumPy Developers; https://github.com/numpy/numpy/blob/main/LICENSE.txt). Accessed 2026-11-04.
- [S2] NumPy quickstart — NumPy v2.5 Manual. NumPy docs. https://numpy.org/doc/stable/user/quickstart.html . License: BSD-3-Clause (numpy/numpy LICENSE.txt; Copyright (c) 2005-2026, NumPy Developers; https://github.com/numpy/numpy/blob/main/LICENSE.txt). Accessed 2026-11-04.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: NumPy docs, Copies and views — NumPy v2.5 Manual, BSD-3-Clause (numpy/numpy LICENSE.txt; Copyright (c) 2005-2026, NumPy Developers; https://github.com/numpy/numpy/blob/main/LICENSE.txt); NumPy docs, NumPy quickstart — NumPy v2.5 Manual, BSD-3-Clause (numpy/numpy LICENSE.txt; Copyright (c) 2005-2026, NumPy Developers; https://github.com/numpy/numpy/blob/main/LICENSE.txt).
Cite this
iinventedlight. 2026. "NumPy copies versus views." iinventedlight Library, iil:note:vh418676, version of 2026-11-04. https://iinventedlight.com/library/notes/numpy-copies-views/. License: CC-BY-4.0.
@misc{iil_note_vh418676,
author = {{iinventedlight}},
title = {{NumPy copies versus views}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/numpy-copies-views/},
note = {Permanent ID iil:note:vh418676. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/numpy-copies-views.md.