Skip to content
DeepForgeby svx
All problems
EasyTime Seriests-005

Expanding Mean

Problem

Compute the expanding (cumulative) mean of a series. The output at position i is the mean of the first i + 1 observations: sum(x[0:i+1]) / (i + 1).

An empty series yields an empty list.

Hint

Keep a running total instead of recomputing the sum each step.

Test cases

case 1
in: [[1,2,3,4]]
expected: [1,1.5,2,2.5]
case 2
in: [[5]]
expected: [5]
case 3
in: [[2,4,6]]
expected: [2,3,4]
case 4
in: [[]]
expected: []
Starter codePython
def expanding_mean(series):
    # Your code here
    pass

4 test cases · run your code against them in the editor