foundation Estimated learning time: 8 h

3.1 NumPy: arrays, broadcasting, vectorization

You can replace a Python loop with an array operation and see the speed-up.

Before:01. Mathematics for Machine Learning02. Python — Basics to AdvancedUnlocks:05. Classical Machine Learning

NumPy arrays are the substrate of all Python data work — Pandas, sklearn and PyTorch share the same array model — and broadcasting plus vectorisation are what make array code both fast and short. It opens the data module because everything later manipulates arrays underneath. The habit that changes everything is replacing Python loops with array operations; the speedup is routinely a hundredfold, and the shape errors broadcasting throws are teachers, not obstacles.

Work through these

  • ndarray, dtype, shape, strides

    The array type at the centre of numerical Python, along with the element type, the dimensions, and how it is laid out in memory. Understanding the layout explains why some operations are free and others copy everything.

  • Indexing, slicing, fancy and boolean indexing

    Selecting parts of an array by position, by a list of positions, or by a condition. Boolean selection in particular replaces an enormous amount of loop code.

  • Broadcasting rules and shape errors

    The rules that let arrays of different shapes combine, and the error messages that appear when they cannot. Most early array bugs are shape mismatches misread as logic errors.

  • Linear algebra, random, and reproducible seeds

    The built-in linear algebra and random-number facilities, and the seed that makes a random result repeatable. Setting a seed is what makes an experiment checkable by somebody else.

Sign in to keep your progress.

Free resources

Links last checked 29 Aug 2026.

Stuck here?

Ask a mentor. A real person answers, and they can see exactly which topic you're on. Usually within a couple of working days.

Checking your session…

Topics shown in module order.