Chapter 10
Array Computation
Elementwise operations, axis reductions, broadcasting, vectorization, matrix-vector products, matrix-matrix products, and shape mismatch debugging.
What this chapter does
After arrays become ordinary, computation becomes the next habit. This chapter teaches readers to predict NumPy operation shapes before running them.
Lessons
Read these in order.
The chapter opening gives the main idea. Move through these lessons next; each page reuses ideas from the pages before it.
- 01Elementwise Operations
Operations that apply by position, scalar operations, and the difference from dot products.
- 02Reductions Over Axes
Summaries over rows, columns, examples, and features with predictable result shapes.
- 03Broadcasting
Combining compatible shapes, scalar broadcasting, and adding bias vectors to batches.
- 04Vectorization
Replacing some loops with clear array operations and checking small examples.
- 05Matrix-Vector Products
Batch linear scores, row-by-vector products, and the shape rule for feature weights.
- 06Matrix-Matrix Products
Rows against columns, inner dimensions, outer dimensions, and layer-shaped computation.
- 07Shape Mismatch Debugging
Reading shape errors by writing the intended shape equation and naming each axis.
- •Conclusion
The shape prediction habit that prepares for plotting and small experiments.
- •Review
A compact review of elementwise operations, reductions, broadcasting, vectorization, matrix products, and shape debugging.
- •Exercises
Chapter-level practice for predicting and verifying array computation shapes.
You are ready when
- Use elementwise operations deliberately.
- Reduce arrays over named axes.
- Read simple broadcasting cases.
- Replace simple loops with vectorized array operations.
- Predict matrix-vector and matrix-matrix product shapes.
- Debug shape mismatches with shape equations.
Where this leads
- Plotting and Inspection
- Randomness and Reproducibility
- Small Numerical Experiments