All problems
Mean Absolute Change
Problem
Given a numeric series, compute the mean absolute change between consecutive observations: the mean of abs(x[t] - x[t-1]).
Return 0.0 if the series contains fewer than two observations.
Hint
Average the absolute step sizes, not the signed changes.
Test cases
case 1
in: [[1,3,6,10]]
expected: 3
case 2
in: [[5,5,5]]
expected: 0
case 3
in: [[10,7,9]]
expected: 2.5
case 4
in: [[4]]
expected: 0
Starter codePython
def mean_absolute_change(series):
# Your code here
pass4 test cases · run your code against them in the editor