Created
May 17, 2023 09:12
-
-
Save sduff/0c1295f3b039c6da98a5b7249e6bbdc3 to your computer and use it in GitHub Desktop.
Rolling Moving Average
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def r(new_value, old_values): | |
if len(old_values) > 10: | |
old_values.pop(0) | |
old_values.append(new_value) | |
average = sum(old_values) / len(old_values) | |
return average, old_values | |
history = [] | |
for i in range(100): | |
value, history = r(i, history) | |
print(value, history) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment