Review

Reconstruct one numerical path from calibration through named broadcasting, centering, checked equivalence, weighted outputs, and verification.

Begin with the Meaning of the Table

The chapter table has three observations and two sensors. Its shape is (3, 2), so every computation must preserve or deliberately change those two axis meanings.

A result that has a legal shape can still be wrong for the question. Name the axes before deciding that an operation is valid.

Transform Every Position

The calibration raw * 0.5 + 1.0 applies the same two arithmetic steps at every position:

[[ 2.  6.]
 [ 3.  8.]
 [ 4. 10.]]

The result keeps shape (3, 2). Predict one value, the shape, and the dtype before running a whole-array expression.

Broadcast Along a Named Axis

A scalar can be reused at every position. A vector of shape (2,) aligns with the two sensor columns. A column of shape (3, 1) aligns one value with each observation row. NumPy compares dimensions from the right, and dimensions are compatible when they are equal or one of them is 1.

Shape compatibility does not supply meaning. A two-value vector is useful as per-sensor data only because the program states that its entries describe the two sensors in the same order as the table.

Center and Check Each Sensor

The calibrated sensor means are [3, 8]. Subtracting those means from every row gives:

[[-1. -2.]
 [ 0.  0.]
 [ 1.  2.]]

The first centered entry is 2 - 3 = -1. After centering, each sensor mean should be close to zero. Use np.allclose(centered.mean(axis=0), 0.0) because floating-point arithmetic can leave tiny rounding differences.

Compare Two Expressions through Evidence

A loop can serve as a readable reference calculation. The whole-array form is acceptable when both forms produce the same intended values and shape. Use np.array_equal when exact equality is expected. Use np.allclose when floating-point rounding may differ. A loop remains the clearer choice when iterations have different rules, stop early, or carry state that the array expression would hide.

Expand a Weighted Score before Using @

For centered row [-1, -2] and weights [1, 0.5], the weighted score is:

(-1 * 1) + (-2 * 0.5) = -2

centered @ weights repeats that visible products-and-sum calculation for every observation and returns shape (3,). With several weight columns, each column defines another weighted score. The result axes are observations and outputs. A bias of shape (2,) then adds one value to each output column.

Verify the Complete Pipeline

Check more than the absence of an exception:

  1. confirm the expected input and output shapes;
  2. state what every axis means;
  3. check that all values are finite;
  4. verify the centered sensor means are near zero;
  5. calculate one score by hand; and
  6. compare the complete result with a small expected array.

Centering with axis=1 runs, but it answers a different question: it centers the two sensors within each observation. The per-sensor invariant exposes that wrong-but-running orientation.

Pause and reflect

What can you now explain without looking back, and what should you revisit? The note stays with this review.

Review

Not marked done.