Concept Flow - Single element access
Create numpy array
Specify index positions
Access element at index
Return single element value
Accessing a single element in a numpy array involves specifying its index and retrieving the value stored there.
import numpy as np arr = np.array([10, 20, 30, 40]) element = arr[2] print(element)
| Step | Action | Index Accessed | Value Retrieved | Output |
|---|---|---|---|---|
| 1 | Create numpy array | - | [10, 20, 30, 40] | - |
| 2 | Access element at index 2 | 2 | 30 | 30 |
| 3 | Print element | - | - | 30 |
| 4 | End | - | - | - |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| arr | undefined | [10 20 30 40] | [10 20 30 40] | [10 20 30 40] |
| element | undefined | undefined | 30 | 30 |
Single element access in numpy: - Use arr[index] to get element - Indexing starts at 0 - Returns the value at that position - Out-of-range index causes error - Works for 1D and multi-D arrays