Getting values out of an array is the day-to-day of analysis. NumPy indexing is richer than a list's, especially in more than one dimension where you index each axis with a comma.
1-D indexing
a = np.array([10, 20, 30, 40])a[0] # 10 firsta[-1] # 40 last (negative counts from the end)
Multi-dimensional indexing
For 2-D, use [row, col] — cleaner than the chained [row][col] you'd write for nested lists:
b = np.array([[1, 2, 3],[4, 5, 6]])b[0, 2] # 3 row 0, column 2b[1] # [4 5 6] a whole rowb[1] = 0 # assign a whole row → [[1 2 3] [0 0 0]]
Key takeaways
- 01Index from 0; negative indices count from the end.
- 02For N-D arrays, index each axis with a comma: b[row, col].
- 03A single index on a 2-D array returns a whole row.
- 04You can assign through an index to update elements or whole rows.
