Stage 1 · Lesson 4 of 8
Vectorisation and broadcasting
means working on a whole array in one go, such as prices * quantities, instead of looping over items one by one in Python. The looping still happens, but inside fast compiled C code, which is often 50 to 100 times faster. Broadcasting is the rule that lets arrays of different shapes combine.
lines the shapes up from the right, and each pair of sizes must be equal or one of them must be 1. So you can subtract a (4,) array of column means from a (1000, 4) array, and every row gets centred. You will carry this way of thinking into pandas and .
Common trapbroadcasting that works when you did not mean it to: (1000,) minus (1000, 1) quietly gives a (1000, 1000) array instead of an error.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking Python Fundamentals
Design Gurus · Beginner · $50
Core Python with an exercise after nearly every lesson, before the data libraries
- BookFreePython for Data Analysis, 3rd Edition
Wes McKinney · Beginner
Free online: NumPy, pandas and plotting from pandas' own creator