Created
June 24, 2013 21:33
-
-
Save jsatt/5853801 to your computer and use it in GitHub Desktop.
running average in python
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 running_sum_generator(iterable): | |
sum = 0 | |
for i in iterable: | |
if not i: | |
continue | |
sum += i | |
yield sum | |
def running_avg(value_list): | |
return [float(sum) / (i + 1) for (i, sum) in | |
enumerate(running_sum_generator(value_list))] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment