NumPy indexing and slicing basics
Answer: ndarrays can be indexed using the standard Python x[obj] syntax, where x is the array and obj the selection. Single element indexing works exactly like that for other standard Python sequences: it is 0-based, and accepts negative indices for indexing from the end of the array. (S1)
Multiple dimensions
- It is not necessary to separate each dimension's index into its own set of square brackets. (S1)
- If one indexes a multidimensional array with fewer indices than dimensions, one gets a subdimensional array. (S1)
- An element of the array can be accessed by specifying the index along each axis within a single set of square brackets, separated by commas. (S2)
- For two-dimensional arrays, a better mental model is to think of the column index as coming last and the row index as second to last. (S2)
Slices are views
- Python slice notation can be used for indexing. (S2)
- One major difference is that slice indexing of a list copies the elements into a new list, but slicing an array returns a view: an object that refers to the data in the original array. (S2)
- The original array can be mutated using the view. (S2)
- In the subdimensional case, the returned array is a view, i.e., it is not a copy of the original, but points to the same values in memory as does the original array. (S1)
Claims
- id: C1 claim: NumPy indexing is 0-based and accepts negative indices. source: S1 evidence: "and accepts negative indices for indexing from the end of the array."
- id: C2 claim: Fewer indices than dimensions gives a subdimensional array. source: S1 evidence: "one gets a subdimensional array."
- id: C3 claim: Slicing an array returns a view. source: S2 evidence: "but slicing an array returns a view"
- id: C4 claim: The original array can be mutated using the view. source: S2 evidence: "The original array can be mutated using the view."
Sources
- [S1] Indexing on ndarrays — NumPy v2.5 Manual. NumPy docs. https://numpy.org/doc/stable/user/basics.indexing.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: the absolute basics for beginners — NumPy v2.5 Manual. NumPy docs. https://numpy.org/doc/stable/user/absolute_beginners.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, Indexing on ndarrays — 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: the absolute basics for beginners — 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 indexing and slicing basics." iinventedlight Library, iil:note:6jvjq31g, version of 2026-11-04. https://iinventedlight.com/library/notes/numpy-indexing/. License: CC-BY-4.0.
@misc{iil_note_6jvjq31g,
author = {{iinventedlight}},
title = {{NumPy indexing and slicing basics}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/numpy-indexing/},
note = {Permanent ID iil:note:6jvjq31g. 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-indexing.md.