Mark Yourself Question
An oscilloscope records these voltage samples across a resistor:
import numpy as np v = np.array([4.0, -3.0, 2.0, -5.0, 1.0]) # volts
The root-mean-square value of NNN samples is
a) Write a function rms(x) that returns the RMS value of a NumPy array without using a loop.
b) Call it on v and state the result in volts to three decimal places.
c) Explain why np.mean(v) cannot replace it as a measure of signal size.
Unlock full course notes by signing up
Pump energy from sliced arrays
A data logger records a pump's average power over four consecutive intervals. An engineer computes energy with this code:
What value does E hold? Give your answer in kWh to two decimal places.
Splitting a test duration with // and %
A data logger records the duration of a fatigue test as an integer number of seconds. A Python script splits it into hours, minutes and seconds, and also computes one extra value r:
Give the value that Python stores in each of h, m, s and r. Each answer is an exact integer.
Lists versus arrays under multiplication
An engineer intends to double three loads, measured in kN, and checks the results by comparing their totals:
What value does result hold, and what does it reveal about the engineer's check? The tuple contains the number of elements in a, the mean of a in kN, and the mean of b in kN, respectively.
Ranking expressions by operator precedence
Each item below is a complete Python expression typed at the interpreter. Evaluate each one using Python's operator precedence and associativity rules, then arrange the expressions from the smallest resulting value to the largest.