Exercises

Practice checking bounded variation, replaying ordered calls, preserving sampled and shuffled records, saving run evidence, and comparing later runs.

These exercises combine generation, replay, sampling, aligned splitting, saved records, and comparison. State each rule before checking one result.

Q1. Check a bounded noise contract

Complete the property checks for noise that must have shape (3, 2) and stay in the half-open interval [-0.2, 0.2).

Editable Python

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

Ready to run.

HintTranslate the contract directly
Use equality for the shape, >= -0.2 for every lower comparison, and < 0.2 for every upper comparison.
SolutionCheck properties rather than exact values
shape_valid = noise.shape == (3, 2) and range_valid = np.all(noise >= -0.2) and np.all(noise < 0.2).
Not attempted
Review

Not marked done.

Q2. Predict whether two sequences replay

Two generators start from seed 21. The first draws one (3, 2) uniform array. The second draws one scalar before drawing that array. Will the arrays match exactly?

Choose one

Select one choice, then check.

HintTrace generator state
Ask whether both array calls begin from the same state.
SolutionCall order is part of replay
The arrays need not match because the second generator consumed one value first.
Not attempted
Review

Not marked done.

Q3. Avoid accidental reseeding

Which function design lets repeated calls continue one controlled sequence?

Choose one

Select one choice, then check.

HintKeep ownership visible
The caller should decide which generator state the function consumes.
SolutionPass the generator
Define a parameter such as rng, then call rng.uniform(...) inside the function.
Not attempted
Review

Not marked done.

Q4. Apply one sampled index array

Complete the program so the selected IDs and readings stay aligned.

Editable Python

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

Ready to run.

HintReuse the selection
Index both arrays with the same indexes value.
SolutionPreserve record identity
Use selected_ids = record_ids[indexes] and selected_readings = readings[indexes].
Not attempted
Review

Not marked done.

Q5. Read replacement from selected indexes

The sampled indexes are [1, 3, 1]. What does the repeated 1 prove about this particular selection?

Choose one

Select one choice, then check.

HintCompare with no replacement
A no-replacement sample cannot select index 1 twice.
SolutionIdentify the rule from the result
The selection used replacement, so two sample positions may refer to the same source record.
Not attempted
Review

Not marked done.

Q6. Verify a paired split

Complete the disjointness and coverage checks for two groups of shuffled indexes.

Editable Python

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

Ready to run.

HintCheck overlap and the complete set
An empty intersection proves no overlap. Sorted combined indexes should equal np.arange(6).
SolutionVerify both split properties
Set disjoint = np.intersect1d(working, checking).size == 0, combined = np.concatenate([working, checking]), and coverage = np.array_equal(np.sort(combined), np.arange(6)).
Not attempted
Review

Not marked done.

Q7. Make a run record JSON-compatible

Which conversion is needed before json.dumps can store a NumPy index array and a NumPy floating-point mean?

Choose one

Select one choice, then check.

HintUse ordinary Python forms
An array can become a list, and a NumPy scalar can become a Python float.
SolutionConvert at the serialization boundary
Use .tolist() for the index array and float(...) for the scalar mean.
Not attempted
Review

Not marked done.

Q8. Compare replayed outputs correctly

Which comparison pair fits a replayed integer index array and a floating-point measurement array?

Choose one

Select one choice, then check.

HintSeparate discrete and numerical evidence
Indexes name exact positions; floating-point calculations may need tolerance-aware comparison.
SolutionUse each comparison for its job
Use np.array_equal(replayed_indexes, saved_indexes) and np.allclose(replayed_values, saved_values).
Not attempted
Review

Not marked done.

Q9. Find the first failed replay position

The saved indexes are [4, 1, 5] and the replayed indexes are [4, 2, 5]. What is the first mismatching array index?

Compute it first, then check your number.

HintCheck in order
Position zero agrees. Inspect the next position.
SolutionLocate the first divergence
The first mismatch is at array index 1. Check configuration and call order before that selection.
Not attempted
Review

Not marked done.

Q10. Distinguish replay from controlled comparison

Run B uses the same data, seed, and call order as Run A but deliberately changes the noise upper bound from 0.2 to 0.3. What kind of run is B?

Choose one

Select one choice, then check.

HintAsk whether agreement is expected
The run is designed to measure the effect of one changed setting.
SolutionName the comparison honestly
Run B is a controlled comparison, not a reproduction. Its record should identify noise_high as the changed setting.
Not attempted
Review

Not marked done.

You can now add bounded variation, replay its ordered generator calls, sample and split aligned records, save the settings and evidence, and decide whether a later run is a reproduction or a controlled comparison. This completes the Python Core path and leaves a repeatable numerical experiment ready for Mathematics.

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.