Module 2 · Lesson 2 of 56/56 in the course~18 min
Module lessons (2/5)
Indexing and broadcasting
Lesson preview5 hands-on exercises readyMachine Learning: from first principles to practice · Module 2 — Toolkit: numpy, statistics and pandas
Slicing, boolean masks and broadcasting for selecting and combining data.
What you'll learn in this lesson
- Select rows, columns and sub-blocks with slicing.
- Filter values with a boolean mask.
- Use broadcasting to combine arrays of different shapes.
Overview
Real data work is mostly selection: "all rows where the age is over 30", "only the last two columns", "subtract the average of each column". numpy handles all of it with a compact syntax.
For a 2-D array, you write a[rows, columns], where each part can be a slice start:stop (stop excluded).
Sections covered in this lesson
- 1The hook: choosing what you need
- 2Slicing
- 3Interactive lab: broadcasting & slices
- 4Shape alignment table for shape
(4, 3) - 5Boolean masks
- 6Broadcasting
Pro Lesson · Module 2 — Toolkit: numpy, statistics and pandas
Unlock "Indexing and broadcasting" and the full Machine Learning: from first principles to practice curriculum
Slicing, boolean masks and broadcasting for selecting and combining data.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Machine Learning: from first principles to practice plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.