All problems
Rolling Mean
Problem
Return the mean of every consecutive window of length window over data. Return an empty list when window <= 0 or window > len(data).
Hint
Slide the window and average each slice.
Test cases
case 1
in: [[1,2,3,4,5],3]
expected: [2,3,4]
case 2
in: [[1,2,3],1]
expected: [1,2,3]
case 3
in: [[1,2],3]
expected: []
case 4
in: [[4,4,4,4],2]
expected: [4,4,4]
case 5
in: [[1,2,3,4],2]
expected: [1.5,2.5,3.5]
Starter codePython
def rolling_mean(data, window):
# Your code here
pass5 test cases · run your code against them in the editor