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.7.0 ·

Array bugs often return plausible numbers. Use unequal dimensions and hand-computed rows so that a successful operation cannot hide a mistaken meaning. Carry that habit into preprocessing and model inputs.

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.

Normalize a matrix with a constant feature and one masked observation. What should the constant feature and the mean denominator do?

Compare an approach

Define the constant-feature policy before division, for example a unit fallback scale. Compute statistics only from valid observations; masking the final output alone leaves the fitted statistics contaminated. Reject a feature with no valid observations or declare an explicit policy.

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.