Reset state between independent runs

Two test runs contain equally weighted torque readings in N⋅m\text{N}\cdot\text{m}:


Python
runs = [[2.0, 4.0], [6.0, 8.0, 10.0]]


A function is intended to return one independent mean for each run, but currently combines state across runs:


Python
def run_means(runs):
    total = 0.0
    count = 0
    means = []
    for run in runs:
        for value in run:
            total += value
            count += 1
        means.append(total / count)
    return means


Which reset strategy gives the intended independent means? In each proposed change, any reset inside the outer loop occurs immediately before the inner loop, and all other statements remain as shown.

Choose an answer

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 Programming Techniques for Data Analysis Questions: