Course · Arrays & pure functionsPhase 01 · Study guide

Can you spot a wrong axis even when the program runs?

Core Foundation · Local CPULaptop CPU4 lessons (~3.1h)

Revision v0.18.1 ·

An array carries a meaning as well as a shape. If rows are observations and columns are features, a mean over rows answers a different question from a mean over columns. Broadcasting can complete successfully while adding an observation bias where a feature bias was intended. Use unequal dimensions and one hand-computed row throughout this chapter. Follow training statistics into a new batch, keep the caller's inputs intact, and distinguish replacing an indexed value from accumulating repeated contributions. These habits become the input contract for every later model.

Preparation: Setup & first steps

Runtime: CPU

Check your starting point

A matrix has three observations and two features. You need one mean per feature. Which axis should be reduced, and how many values remain?

Compare your reasoning

Reduce the observation axis, axis 0. Two feature means remain. Reducing axis 1 instead returns three observation means, which answers a different question.

If this is unfamiliar, work through From NumPy to jax.numpy before attempting the project.

Build in stages

1. Write the data contract

Annotate observation and feature axes; calculate one normalized row by hand. Compare a feature bias with an observation bias using unequal dimensions.

2. Make preprocessing safe to reuse

Pass parameters explicitly, preserve the caller’s arrays and check indexed accumulation separately from replacement. Carry shape, mask and valid-count checks into foundation-toolkit stage 2.

Try a changed condition

Make a prediction before opening the reasoning. Keep your answer and the evidence you would collect.

Use rows (1,3)(1,3), (5,7)(5,7), (100,200)(100,200), with the last row masked. Predict feature means and population variances. Then select only the first row.

Compare an approach

With two valid rows the means are (3,5)(3,5), variances (4,4)(4,4), and count 2. Selecting only the first row gives means (1,3)(1,3), variances (0,0)(0,0), count 1. Dividing by all three rows is a denominator bug. A zero valid count needs rejection or an explicitly declared policy before division.

Diagnose a likely failure

Symptom: Predictions look reasonable but adding a bias changes the wrong dimension.

Check next: Write the two shapes before broadcasting and test one row and one column independently.

Decide what is ready

Retain unequal-shape, constant-column and masked-row cases, a NumPy or hand reference, and proof that inputs were unchanged. Explain every axis in the output.

Where to put your project code

Write your code in: projects/arrays-audit/starter/model.py (copy projects/arrays-audit/starter/model.py first: cp projects/arrays-audit/starter/model.py projects/arrays-audit/starter/model.py).

Verify your implementation: python3 projects/arrays-audit/tests/check.py --stage all --impl projects/arrays-audit/starter/model.py

Run the staged project checks on your implementation in projects/arrays-audit/starter/model.py and record your transfer experiment results in your portfolio.

Open Audit masked batch moments and padding-sensitive denominators

Open Connect arrays, transformations and explicit state

What still needs further work

Sparse and ragged inputs need additional contract-focused labs; this phase deliberately teaches fixed dense arrays first.