Section 2 of 12 · 14 lessons

Python and NumPy

The courses use Python and NumPy to turn the ideas into calculations we can inspect. We will begin with a few greenhouse readings, learn how to store and select them, then work through array shapes, summaries, matrix calculations, and numerical checks. We will also make the code reusable and keep enough of each experiment to run it again. The examples and challenges run here in the browser.

0 of 14 finished

From a measurement to a calculation

Before asking a model to learn from numbers, we need to put those numbers in a form we can inspect. We will keep track of what each entry represents as we calculate with arrays.

  1. 01Giving Measurements a PlaceThree thermometers give us three readings. Before we can calculate with them, we need to decide how those readings are stored, which position belongs to which thermometer, and what an operation should do to the collection.
  2. 02Which Direction Are We Adding?A table can hold several greenhouses across several days. Adding across a row answers a different question from adding down a column. We need to keep that distinction when we ask an array to calculate.
  3. 03Preparing the Arrays We NeedBotie needs a place for tomorrow's readings and a set of times at which to collect them. We can describe those arrangements directly instead of typing every repeated value ourselves.

Working with whole arrays

A calculation often needs the same reference for many observations, or only the observations meeting a condition. We need to express those choices without losing which values belong together.

  1. 04Choose the Readings Without Losing Their PlaceBotie may need one morning, a run of mornings, or selected greenhouses. We need to express each request precisely and know whether editing the selection will change the original report.
  2. 05Put the Same Readings Into the Right ArrangementA sensor may send one long sequence while a calculation expects rows. We need to change the arrangement without changing which measurements belong to each day and greenhouse.
  3. 06One Reference for Many RowsEach greenhouse has its own target temperature. We want to compare every day's readings with those three targets without copying the targets into a new table by hand.
  4. 07Ask Each Row a QuestionBotie needs the greenhouse readings that reached a temperature limit. A yes-or-no decision for each reading lets us select the relevant observations without losing their order.

Calculations We Will Reuse

Later models will combine feature columns, compare predictions with observations, and summarise their errors. We will calculate those pieces with NumPy and keep their intermediate results visible.

  1. 08Summarise a Report Without Losing the QuestionBotie needs totals, typical readings, and the greenhouse that needs attention first. A value, a position, and an ordered report answer different questions, even when they come from the same array.
  2. 09One Calculation for a Whole ReportBotie applies the same rule to many readings. We will first write the repeated steps, then express them with array operations while keeping the intermediate values and memory costs understandable.
  3. 10Turn Several Measurements Into Several PredictionsA prediction can combine temperature and humidity with separate coefficients. Matrix operations let us apply that same rule to every greenhouse, then check how a fitted rule relates to its observations.

Keep the Calculation Trustworthy

A useful result needs to survive new inputs and another run. We will check numerical agreement, repeat random choices, package calculations in functions, and save the information needed to reconstruct them.

  1. 11When Two Calculations Almost AgreeA tiny rounding difference, a missing observation, and a wrongly shaped result are different problems. We need checks that distinguish them before trusting a numerical answer.
  2. 12Can We Repeat the Same Experiment?Changing both a model and its sampled observations makes it difficult to explain a changed result. We need to keep track of the random choices so we can repeat a comparison.
  3. 13Give a Reusable Calculation a Clear ContractCopying a calculation into every exercise makes mistakes hard to repair. We will put the rule in a function, state what its inputs mean, and check it on more than one report.
  4. 14Keep Enough of a Calculation to Run It AgainA printed table is not a complete experiment record. We will save arrays with their shapes and types, keep related arrays together, and check what survives when a report moves through a text file.