Python Glossary Русский

Python 3.4+statisticsfunction

statistics.stdev

spread

Sample standard deviation (with n−1 degrees of freedom).

Syntax

statistics.stdev(data)

Dividing by n−1 makes this a sample estimate; if your data is the entire population, use pstdev or you will overstate the spread. Fewer than two values raises StatisticsError, and the optional xbar only saves recomputing a mean you already know — pass anything else and the result is silently meaningless.

Examples

import statistics
print(statistics.stdev([2, 4, 4, 4, 5, 5, 7, 9]))   # → 2.138089935299395
print(statistics.stdev([1, 2, 3, 4, 5]))  # → 1.5811388300841898
print(statistics.stdev([1, 2, 3, 4, 5], xbar=3))  # → 1.5811388300841898
print(statistics.stdev([7, 7, 7, 7]))  # → 0.0
print(statistics.stdev([5]))  # → StatisticsError
print(statistics.pstdev([1, 2, 3, 4, 5]))  # → 1.4142135623730951

See also

Open in the full glossarydocs.python.orgReport an inaccuracy