Python and NumPy

Reuse the training reference on another report

BOTIE

Calculate the mean of the training readings, subtract it from the new report, and collect the reference and transformed report together in that order.
Ready to test
0 passed · 0 failed · 2 not run

An empty floor. Start with the information your machine needs.

Received result

Your answer will arrive here.

Examples, experiments and workspace controls
Live values

Connect a tool's inputs to see what it produces. You can try a branch before connecting it to Result.

Try your own inputs

Use a copy of the example to try your own data. Keep the problem's assumptions in mind, and predict the effect of a change before checking the output. You can also add another branch to compare two ways of doing the calculation.

Start at an output arrow, then click or drag to an input. Drag empty space to pan. Delete removes a selection. Ctrl/Cmd+Z undoes a change.
Context for this challenge

Calculate the mean of the training readings, subtract it from the new report, and collect the reference and transformed report together in that order.

A reusable transformation should return both the training reference and the new report expressed relative to it. Botie needs a clear output contract.

Compute the training mean, subtract it from the new report, and collect the mean before the transformed report.

Examples and results
Training readings
  1. 010
  2. 114
New report
  1. 012
  2. 118
Required result
[
  12,
  [
    0,
    6
  ]
]
Training readings
  1. 08
  2. 112
  3. 216
New report
  1. 011
  2. 117
Required result
[
  12,
  [
    -1,
    5
  ]
]
Try a fresh construction

This clears this draft, including its undo history. Earlier successful attempts stay recorded. Build again without opening hints to record an independent attempt.

Stuck? Inspect a worked construction

The tools below form one possible solution. You can assemble it, follow its signals, and undo that change to return to your own construction.

Assumptions and test precision

Workshop cases satisfy the finite, nonempty vector contract. Python is where we define functions and handle invalid inputs. Numerical tests allow a difference of 0.001. Lists and structures must also have the right shape.

Repeated training values and a centred report

This check uses the pieces from “Return a reference with the values it explains”.

BOTIE

Predict the returned training reference and transformed report. Repeated training readings remain observations, and the report cannot set its own reference.
Training readings
  1. 04
  2. 14
  3. 210
New report
  1. 06
  2. 16
  3. 20

Use a number, text, or an array matching the requested result. For a matrix, put each row in brackets. Saving your prediction runs your current construction on these inputs and checks the earlier examples too.

Build a construction in the workspace above first. This case will test those pieces.

What inputs and output order would you state before translating this construction into a Python function?

Specify a reusable calculation's fitted state, transformed output and invalid-input behaviour separately.

Workshop cases satisfy the finite, nonempty vector contract. Python is where we define functions and handle invalid inputs.

Work through the Python challenges →
Continue the courseKeep Enough of a Calculation to Run It Again →
← Can We Repeat the Same Experiment?