Skip to content

Instantly share code, notes, and snippets.

@gjcourt
Created July 26, 2012 00:24
Show Gist options
  • Save gjcourt/3179554 to your computer and use it in GitHub Desktop.
Save gjcourt/3179554 to your computer and use it in GitHub Desktop.
Rolling mean
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