Created
August 26, 2014 18:53
-
-
Save mteodoro/1ee132a47a141eae54db to your computer and use it in GitHub Desktop.
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
#handy util functions | |
import math | |
class Bunch: | |
def __init__(self, **kwds): | |
self.__dict__.update(kwds) | |
def __repr__(self): | |
args = ['%s=%s' % (k, repr(v)) for (k,v) in vars(self).items()] | |
return 'Bunch(%s)' % ', '.join(args) | |
def mean(lst): | |
"""mean(lst) -> the arithmetic mean of the values in LST""" | |
return sum(lst) / float(len(lst)) | |
def variance(lst): | |
"""variance(lst) -> variance of values in LST""" | |
mu = mean(lst) | |
return sum((v - mu) ** 2 for v in lst) / float(len(lst)) | |
def stddev(lst): | |
"""stddev(lst) -> standard deviation of values in LST""" | |
return math.sqrt(variance(lst)) | |
def init_completion(): | |
try: | |
import readline | |
except ImportError: | |
print "Module readline not available." | |
else: | |
import rlcompleter | |
readline.parse_and_bind("tab: complete") | |
def repl(local=None): | |
"""start a repl. use: repl(local=locals()) to get current env. | |
if IPython is available, use: | |
import IPython; IPython.embed()""" | |
import code | |
init_completion() | |
code.interact(local=local) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment