Writing a vectorized RMS function

Mark Yourself Question

  1. Grab a piece of paper and try this problem yourself.
  2. When you're done, check the "I have answered this question" box below.
  3. View the solution and report whether you got it right or wrong.

An oscilloscope records these voltage samples across a resistor:


Python
import numpy as np
v = np.array([4.0, -3.0, 2.0, -5.0, 1.0])   # volts


The root-mean-square value of NN samples is


Vrms=1N∑i=1Nvi2V_{\text{rms}} = \sqrt{\frac{1}{N}\sum_{i=1}^{N} v_i^2}


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.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Python Programming Questions: