Chapter 10

Array Computation

Elementwise operations, axis reductions, broadcasting, vectorization, matrix-vector products, matrix-matrix products, and shape mismatch debugging.

Subject
Python
Lessons
7 lessons
Practice
12 checks
Review
3 pages

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.

  1. 01
    Elementwise Operations

    Operations that apply by position, scalar operations, and the difference from dot products.

  2. 02
    Reductions Over Axes

    Summaries over rows, columns, examples, and features with predictable result shapes.

  3. 03
    Broadcasting

    Combining compatible shapes, scalar broadcasting, and adding bias vectors to batches.

  4. 04
    Vectorization

    Replacing some loops with clear array operations and checking small examples.

  5. 05
    Matrix-Vector Products

    Batch linear scores, row-by-vector products, and the shape rule for feature weights.

  6. 06
    Matrix-Matrix Products

    Rows against columns, inner dimensions, outer dimensions, and layer-shaped computation.

  7. 07
    Shape Mismatch Debugging

    Reading shape errors by writing the intended shape equation and naming each axis.

  1. Conclusion

    The shape prediction habit that prepares for plotting and small experiments.

  2. Review

    A compact review of elementwise operations, reductions, broadcasting, vectorization, matrix products, and shape debugging.

  3. 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

Chapter progress