Concept Flow - 2D array indexing (row, col)
Create 2D array
Choose row index
Choose column index
Access element at (row, col)
Return element value
We start with a 2D array, pick a row and column index, then access the element at that position.
import numpy as np arr = np.array([[10,20,30],[40,50,60],[70,80,90]]) element = arr[1,2] print(element)
| Step | Action | Row Index | Column Index | Element Accessed | Output |
|---|---|---|---|---|---|
| 1 | Create 2D array | - | - | - | [[10 20 30] [40 50 60] [70 80 90]] |
| 2 | Select row index | 1 | - | - | - |
| 3 | Select column index | 1 | 2 | - | - |
| 4 | Access element at (1,2) | 1 | 2 | arr[1,2] | 60 |
| 5 | Print element | - | - | - | 60 |
| Variable | Start | After Step 1 | After Step 4 | Final |
|---|---|---|---|---|
| arr | undefined | [[10 20 30] [40 50 60] [70 80 90]] | [[10 20 30] [40 50 60] [70 80 90]] | [[10 20 30] [40 50 60] [70 80 90]] |
| element | undefined | undefined | 60 | 60 |
| row index | undefined | undefined | 1 | 1 |
| column index | undefined | undefined | 2 | 2 |
2D array indexing syntax: arr[row, col] Indices start at 0 (zero-based). Access element by specifying row then column. Out-of-range indices cause errors. arr[1,2] accesses 2nd row, 3rd column element. Use arr[row, col] for efficient access.