/Curriculum/Core NumPyData Access

08. NumPy IndexingBeginner

Zero-based indexing, negative indexing, and multi-dimensional matrix coordinate selection.

12 mins

Concept Overview

NumPy arrays use zero-based indexing. Multi-dimensional elements are accessed with clean comma-separated coordinates `arr[row, col]`.

Hardware Mental Model

Think of 2D indexing `arr[row, col]` like battleship coordinates: first pick the horizontal row tier, then pinpoint the vertical column slot.

Key Concepts (1)Click snippet to load in editor

NumPy uses `matrix[row, col]` instead of standard Python nested brackets `matrix[row][col]`. Comma syntax is faster and cleaner.

val = matrix[0, 1]

⚠ Common Mistakes & Pitfalls

Avoid these frequent beginner syntax and logic traps
❌ Incorrect:val = matrix[1][2] # Slower Python double lookup
✓ Correct:val = matrix[1, 2]

Using `matrix[row, col]` accesses C-level memory in a single pointer jump.

Pro Tip: Always use comma-separated indexing `arr[r, c]` in NumPy.

📌 Quick Revision

Core takeaway points from this topic
0-indexed: First element is at index 0.
Negative index: -1 is the last element.
2D coordinate access: `arr[row_idx, col_idx]`.
Editor: 08. NumPy Indexing
Python ● Ready
Initializing Python IDE...
Ctrl+Enter
Execution Result
Click "RUN CODE" to execute and inspect array state

🎯 Try It Yourself: Practice Challenge

Hands-on Mode

Solve the objective below using NumPy vectorized syntax

Objective:Select Specific Element

Given `arr = np.array([[5, 10], [15, 20]])`, access the element at row 1, column 0 (value 15) and print it.

Expected Output Target:15
Practice Workspace
Python ● Ready
Initializing Python IDE...
Ctrl+Enter
Execution Result
Click "RUN CODE" to execute and inspect array state