← NumPy
Lesson 2 of 3
Maths on arrays
Watch, read the card, then practise. Maths on whole arrays · Sum, mean, max and more · Broadcasting
The video for this lesson is being recorded.
Meanwhile, the notes below and the 60-second cards cover the same ideas.
Practise this topicMaths on whole arrays
Maths on an array works on every value at once, with no loop needed.
Remember: No for loops: let NumPy do the whole array.
Sum, mean, max and more
Aggregations squash an array into one number, or one number per row or column.
Remember: axis=0 → one result per column. axis=1 → one per row.
Broadcasting
Broadcasting lets NumPy combine arrays of different shapes by stretching the smaller one.
Remember: Line the shapes up from the right; each pair must be equal or 1.
Try the example in Code Lab
import numpy as np a = np.array([1, 2, 3]) b = np.array([10, 20, 30]) print((a * 2).tolist(), (a + b).tolist(), int(a @ b))