def stdev(data, m=None): """stdev(iterable_of_numbers [, m]) -> standard deviation of numbers stdev(iterable_of_rows [, m]) -> standard deviation of columns Returns the sample standard deviation (with N-1 degrees of freedom) of the given numbers or columns. The standard deviation is the square root of the variance. Optional argument ``m`` has the same meaning as for ``variance``. >>> stdev([1.5, 2.5, 2.5, 2.75, 3.25, 4.75]) #doctest: +ELLIPSIS 1.08108741552... >>> data = [[0, 1, 2], ... [1, 1, 3], ... [1, 2, 5], ... [2, 4, 6]] ... >>> stdev(data) #doctest: +ELLIPSIS [0.816496580927..., 1.41421356237..., 1.82574185835...] Note that although ``variance`` is an unbiased estimate for the population variance, ``stdev`` itself is *not* unbiased. """ svar = variance(data, m) return v.sqrt(svar)
def quadratic_mean(data): """quadratic_mean(iterable_of_numbers) -> quadratic mean of numbers quadratic_mean(iterable_of_rows) -> quadratic means of columns Return the quadratic mean of the given numbers or columns. >>> quadratic_mean([2, 2, 4, 5]) 3.5 The quadratic mean, or RMS (Root Mean Square), is the square root of the arithmetic mean of the squares of the data. It is a type of average best used to get an average absolute magnitude when quantities vary from positive to negative: >>> quadratic_mean([-3, -2, 0, 2, 3]) 2.280350850198276 When passed an iterable of sequences, each inner sequence represents a row of data, and ``quadratic_mean`` operates on each column. All rows must have the same number of columns, or ValueError is raised. >>> data = [[0, 1, 2, 4], ... [1, 2, 4, 6], ... [2, 4, 6, 6]] ... >>> quadratic_mean(data) #doctest: +ELLIPSIS [1.29099..., 2.64575..., 4.3204..., 5.41602...] """ count, total = stats._len_sum(v.sqr(x) for x in data) if not count: raise stats.StatsError( 'quadratic mean of empty sequence is not defined') return v.sqrt(v.div(total, count))
def pstdev(data, m=None): """pstdev(iterable_of_numbers [, m]) -> population std dev of numbers pstdev(iterable_of_rows [, m]) -> population std dev of columns Returns the population standard deviation (with N degrees of freedom) of the given numbers or columns. The standard deviation is the square root of the variance. Optional argument ``m`` has the same meaning as for ``pvariance``. >>> pstdev([1.5, 2.5, 2.5, 2.75, 3.25, 4.75]) #doctest: +ELLIPSIS 0.986893273527... >>> data = [[0, 1, 2], ... [1, 1, 3], ... [1, 2, 5], ... [2, 4, 6]] ... >>> pstdev(data) #doctest: +ELLIPSIS [0.707106781186..., 1.22474487139..., 1.58113883008...] """ pvar = pvariance(data, m) return v.sqrt(pvar)