All problems
Loss Moving Average
Problem
Compute a trailing moving average of a loss sequence.
For each index i, average losses[max(0, i - window + 1) .. i], so early entries use fewer values. Return the list of averages; an empty input returns [].
Hint
At the start of the sequence the window is smaller than requested.
Test cases
case 1
in: [[1,3,5,7],2]
expected: [1,2,4,6]
case 2
in: [[2,4],3]
expected: [2,3]
case 3
in: [[],2]
expected: []
case 4
in: [[5],2]
expected: [5]
Starter codePython
def loss_moving_average(losses, window):
# Your code here
pass4 test cases · run your code against them in the editor