+def _mean(iterable): # missing-numpy workaround
+ """Return the mean of a list of items.
+
+ >>> print(_mean([0,1,2,3,4,5,6]))
+ 3.0
+ """
+ length = len(iterable)
+ return sum(iterable) / float(length)
+
+def _std(iterable): # missing-numpy workaround
+ """Return the standard deviation of a list of items.
+
+ >>> print(_std([0,1,2,3,4,5,6]))
+ 2.0
+ """
+ length = len(iterable)
+ m = _mean(iterable)
+ return _math.sqrt(sum((x-m)**2 for x in iterable) / length)
+
+if _numpy is None:
+ _statistics_container = list
+else:
+ _statistics_container = _numpy.array
+
+def _statistic(iterabale, statistic):
+ """Calculate statistics on an list of numbers
+ """
+ global _numpy_import_error
+ if _numpy_import_error:
+ assert _numpy_import_error is not None
+ _LOG.warning('error importing numpy, falling back to workarounds')
+ _LOG.warning(str(_numpy_import_error))
+ _numpy_import_error = None
+ if stat == 'Mean':
+ if _numpy is None: # work around missing numpy
+ return _mean(iterable)
+ else:
+ return gs.mean()
+ elif stat == 'Std. Dev.':
+ if _numpy is None: # work around missing numpy
+ sval = _std(iterable)
+ else:
+ return gs.std()
+ else:
+ raise NotImplementedError(stat)
+