Vectorised computing
Element-wise arithmetic and ufuncs, broadcasting rules for arrays of different shapes, and reductions along axes.
About 5 hours of study
Learning objectives
- Replace loops with element-wise operations
- Predict broadcast shapes
- Reduce along the right axis
Lessons
- 1
Vectorised arithmetic and ufuncs Intermediate
Arithmetic operators that work element by element, operations with a single number, universal functions such as sqrt and exp, division by zero producing inf and nan, and why vectorised code replaces loops.
- 2
Broadcasting Advanced
How NumPy combines arrays of different shapes: lining shapes up from the right, stretching dimensions of size 1, the error when shapes do not fit, and common uses such as centring columns and building tables.
- 3
Reductions along axes Intermediate
Summarising arrays with sum, mean, min, max, std, argmin and argmax, choosing an axis to reduce along, keeping dimensions with keepdims, and running totals with cumsum.
Module practice
- NumPy: Operations with a scalarEasy
- NumPy: Division with inf and nanMedium
- NumPy: Universal functions on the edgesHard
- NumPy: Broadcast two shapesEasy
- NumPy: Add a row, a column or a numberMedium
- NumPy: Broadcast many shapes and find what stretchesHard
- NumPy: Sums along each axisEasy
- NumPy: min, max, mean and argmax along an axisMedium
- NumPy: Row percentages with keepdimsHard