Sensor Readings
Part of the Data and Plots section of Coddy's Machine Learning journey. Lesson 58 of 60.
A sensor logs a server room's temperature every hour, from hour 0 (midnight) to 23. When a reading fails, it writes -999 instead.
The technician wants each day summed up with the failures left out, and drawn like Monday's (day 1):
Above 25 C, the room needs attention.
Challenge
HardThe starter holds four days of readings in week, one row per day, and reads a day number, 1 to 4.
- Print how many of that day's readings failed.
- Print the mean of the good readings, rounded to 1 decimal with
np.round, and how many are abovelimit. - Print the warmest hour and its reading.
- Draw the good readings against their hours with the
fig, axform, titledServer Room Temperature, labelledHourandTemperature (C).
For day 1, the whole output is:
Failed readings: 3
Average: 21.9
Hours above 25: 7
Warmest: hour 14 at 29.4
Charts drawn: 1
Title: Server Room Temperature
X label: Hour
Y label: Temperature (C)
Lines: 1
Across (x): [0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23]
Up (y): [17.2, 16.8, 16.5, 16.1, 16.4, 17.9, 19.6, 21.8, 23.5, 25.1, 27.9, 28.8, 29.4, 28.7, 27.2, 25.6, 23.9, 21, 19.8, 18.6, 17.9]Try it yourself
import numpy as np
import matplotlib.pyplot as plt
# Server room temperature (C) at hours 0 to 23, one row per day; -999 means the reading failed
week = np.array([
[17.2, 16.8, 16.5, -999, 16.1, 16.4, 17.9, 19.6, 21.8, 23.5, 25.1, -999,
27.9, 28.8, 29.4, 28.7, 27.2, 25.6, 23.9, -999, 21.0, 19.8, 18.6, 17.9],
[-999, 17.4, 17.0, 16.7, 16.6, 17.0, 18.2, 19.9, 21.5, -999, 24.6, 26.0,
27.1, 27.8, 28.0, 28.3, 26.4, -999, 23.1, 21.7, 20.5, 19.4, 18.8, 18.1],
[18.3, 18.0, 17.8, 17.5, 17.6, -999, -999, 20.4, 22.9, 25.3, 27.6, 29.5,
31.0, 32.2, 32.9, 33.1, 32.4, 30.8, 28.7, 26.5, 24.6, 22.8, 21.3, 20.1],
[16.9, 16.5, 16.2, 16.0, 15.8, 16.1, 16.9, 18.0, 19.4, 20.8, 22.3, 23.6,
24.7, 26.2, 25.8, 25.1, 24.0, 22.6, 21.3, 20.2, 19.3, 18.5, 17.8, -999],
])
day = int(input())
limit = 25
# Write your code below
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Data and Plots
2NumPy Arrays
Creating ArraysShape and SizeRanges of NumbersIndexing and SlicingRecap: Temperature GridPractice on your own: Online Python compiler