NumPy Array Indexing
An index selects a position, starting at zero. For a multidimensional array, give one coordinate per axis to select a particular measurement.
How it works
Negative indices count from the end of an axis, which can be useful for the latest reading. An out-of-range scalar index raises IndexError; it should not be silently converted to another position. Keep the row and column meanings next to the fixture so a number such as [1, 2] remains understandable. A row selection and a single-coordinate selection have different result shapes.
Run the code
Select Try in playground to preload the complete code into the NumPy editor. Nothing executes on import; choose Run when ready. The first execution loads the local Pyodide runtime and NumPy package. Each ordinary run starts fresh, with no access to this page’s cookies or personal files. In-memory streams and temporary virtual files belong to the runtime, not your PC.
For local work, use a separate virtual environment and run python indexing.py. Download the complete source. The reviewed local environment uses Python 3.12.14 and NumPy 2.5.4; the browser uses Pyodide 0.27.7 with NumPy 2.0.2. Compatible examples are checked in both. See the environment setup. No Apache or database server is required.
Example
import numpy as np
litres = np.array([[12, 18, 24], [6, 9, 15]])
print(int(litres[1, 2]))
print(litres[0].tolist())
try:
litres[2, 0]
except IndexError:
print("Rejected missing site")
Expected result
15 [12, 18, 24] Rejected missing site
The second site’s third day contains fifteen litres. Selecting row zero returns three readings, while the invalid site coordinate is rejected. That distinction is useful when a caller supplies an index rather than a stable record identifier.
Use NumPy’s official reference for precise contracts, supported versions and numerical limitations.