Created
July 26, 2012 00:24
-
-
Save gjcourt/3179554 to your computer and use it in GitHub Desktop.
Rolling mean
This file contains hidden or 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
class RollingMean(object): | |
count = 0 | |
average = 0 | |
@property | |
def val(self): | |
return self.average | |
def add(self, value): | |
self.average = (value + self.count * self.average) / (self.count + 1) | |
self.count += 1 | |
return self.average | |
def reset(self): | |
self.count = 0 | |
self.average = 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment