WeCodeAcademy

Broadcasting

Broadcasting is how NumPy combines arrays of different shapes. A smaller array is stretched to match the bigger one, as long as the shapes line up from the right: each pair of sizes must be equal, or one of them must be 1. A single number broadcasts against anything; a row broadcasts down every row of a grid; a column (shape (n, 1)) broadcasts across every column.

Examplepython
Open in editor »
Quick check

Can an array of shape (2, 3) be added to one of shape (3,)?

Your turn: write the code

Subtract each column's average from the grid (grid minus grid.mean(axis=0)) and print the result.

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.