NumPy & Vectorization

Broadcasting, striding, and deleting the loop — the skill every framework is built on top of.

Module 02.2 · Beginner
Free

8h · 7 lessons · 1 challenge

Before this: Linear Algebra for Machine Learning, Python for ML Engineers

About this module

Broadcasting is the single most useful and most misunderstood rule in array programming. This module drills it until the rules are automatic, because the same rules govern PyTorch tensors, JAX arrays and every kernel you will later write.

The through-line is loop elimination: take working loop-based code and vectorize it, then measure. Most learners find their first hundredfold speedup here.

After this module you can

7 lessons

Lesson 1
Arrays, dtypes, views and copies
Kind
Concept
Length
45 min
Lesson 2
Broadcasting, rule by rule
Kind
Concept
Length
50 min
Lesson 3
Broadcast or Break: predict the shape
Kind
Interactive
Length
30 min
Lesson 4
Indexing, masking and fancy selection
Kind
Concept
Length
45 min
Lesson 5
Delete the loop: five vectorization patterns
Kind
Lab
Length
80 min
Lesson 6
Strides, memory layout and why order matters
Kind
Concept
Length
40 min
Lesson 7
Checkpoint: vectorize this function
Kind
Checkpoint
Length
25 min

The challenge: Broadcast or Break

Two shapes appear. Broadcast, error, or a shape you must name — answer before the timer runs out. Streaks multiply your score.

Worth 300 XP.

Related modules

All modules