Commits

James Mills  committed 4477a14

pymills.mathtools: New module containing simple, useful math routines

  • Participants
  • Parent commits 9d0a7fb

Comments (0)

Files changed (1)

File pymills/mathtools.py

+# Module:	mathtools
+# Date:		27th January 2011
+# Author:	James Mills, prologic at shortcircuit dot net au
+
+"""Math Tools
+
+Module of small useful math tools aka common math routines.
+"""
+
+from math import sqrt
+
+def mean(xs):
+    """Calculate the mean of a list of numbers given by xs"""
+
+    return sum(xs) / len(xs)
+
+def std(xs):
+    """Calculate the standard deviation of a list of numbers give by xs"""
+
+    m = mean(xs)
+    dxs = (x - m for x in xs)
+    qdxs = (x * x for x in dxs)
+    return sqrt(sum(qdxs) / (len(qdxs) - 1))