Exercises

Practice calibration, named broadcasting, centering, equality checks, weighted outputs, bias, and wrong-but-running pipeline repair.

Q1. Predict a calibrated value

The calibration is raw * 0.5 + 1.0. What value replaces raw[1, 1], which is 14.0?

Compute it first, then check your number.

HintWork on one position

Calculate 14.0 * 0.5, then add 1.0.

SolutionApply the two calibration steps

14.0 * 0.5 + 1.0 = 7.0 + 1.0 = 8.0.

Not attempted
Review

Not marked done.

Q2. Align a per-sensor correction

Which shape applies one correction to each sensor column of a table with shape (3, 2)?

Choose one

Select one choice, then check.

HintMatch the sensor axis

Sensors occupy axis 1, whose length is 2.

SolutionUse one value per sensor

Shape (2,) aligns its two entries with the two sensor columns in every row.

Not attempted
Review

Not marked done.

Q3. Align one offset per observation

Complete the offset shape so one value is added across both sensors in each observation.

Editable Python

Command/Ctrl + Enter. Python runs in your browser.

Ready to run.

HintPreserve a length-one sensor axis

Reshape the three offsets to (3, 1).

SolutionMake the observation axis explicit
offsets = np.array([0.0, 0.0, 0.0]).reshape(3, 1)
Not attempted
Review

Not marked done.

Q4. Reject a semantically wrong broadcast

A table happens to have shape (2, 2): two observations by two sensors. A vector of two observation offsets can broadcast across it. Why is table + offsets still the wrong expression?

Choose one

Select one choice, then check.

HintCompatibility is not meaning

A one-dimensional vector aligns from the right.

SolutionGive observation offsets a column shape

Reshape the offsets to (2, 1) so their entries align with observation rows and repeat across sensors.

Not attempted
Review

Not marked done.

Q5. Center the sensor columns

Complete the calculation and verify that each centered sensor mean is near zero.

Editable Python

Command/Ctrl + Enter. Python runs in your browser.

Ready to run.

HintCombine observations, then subtract

Use calibrated.mean(axis=0), subtract that result, and check centered.mean(axis=0) with np.allclose.

SolutionCenter and check the intended axis
Not attempted
Review

Not marked done.

Q6. Choose an equality check

Which comparison is appropriate when two independently ordered floating-point calculations should agree within small rounding differences?

Choose one

Select one choice, then check.

HintAllow small rounding differences

Use the comparison introduced for floating-point results.

SolutionUse tolerance-aware comparison

np.allclose(actual, expected) checks corresponding numerical values while allowing small floating-point differences.

Not attempted
Review

Not marked done.

Q7. Calculate one weighted score

For centered observation [-1.0, -2.0] and weights [1.0, 0.5], what is the weighted score?

Compute it first, then check your number.

HintExpose both contributions

Calculate -1 * 1 and -2 * 0.5 separately.

SolutionAdd the weighted contributions

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

Not attempted
Review

Not marked done.

Q8. Compute one score per observation

Complete the compact weighted calculation.

Editable Python

Command/Ctrl + Enter. Python runs in your browser.

Ready to run.

HintMatch the sensor dimension

Use centered @ weights.

SolutionApply the weighted sum to every row
scores = centered @ weights
Not attempted
Review

Not marked done.

Q9. Add one bias per output

Complete the two-output calculation and bias addition.

Editable Python

Command/Ctrl + Enter. Python runs in your browser.

Ready to run.

HintKeep the operation order visible

First calculate centered @ weights, then add bias.

SolutionCompute two scores and add two biases
outputs = centered @ weights + bias

The first unshifted row is [-2.0, -1.5]; adding the bias gives [-1.75, -2.0].

Not attempted
Review

Not marked done.

Q10. Repair a wrong-but-running pipeline

The code centers each observation instead of each sensor. Repair the axis and retain the checks.

Editable Python

Command/Ctrl + Enter. Python runs in your browser.

Ready to run.

HintCenter down the observation axis

Per-sensor means combine observations, so change the reduction to axis=0. keepdims=True may remain because it makes the broadcast alignment visible.

SolutionRepair the semantic axis
centered = calibrated - calibrated.mean(axis=0, keepdims=True)

Every check then describes the intended observation-by-sensor pipeline.

Not attempted
Review

Not marked done.

The numerical pipeline now has visible operations and checks for values, shapes, axes, finite results, and one hand calculation. Chapter 12 turns those checked results into plots that answer specific questions.

Pause and reflect

Which exercises were difficult, what mistake pattern did you notice, and what should you practice again? The note stays with this exercise set.

0 of 10 exercises marked done

Review

Not marked done.