Reference · Statistics
stats.stdev
signature
stats.stdev(list, num | null=) -> floatWhat it does
The sample standard deviation of a list of numbers: the square root of
stats.variance, as Python's statistics.stdev.
It is the std that stats.describe reports.
For the whole population use stats.pstdev.
Examples
print(stats.stdev([1, 2, 3, 4]))print(stats.stdev([1.5, 2.5, 2.5, 2.75, 3.25, 4.75]))output
1.29099444873580561.0810874155219827Edge cases
- At least two numbers are needed: one number is an error, not
0.0. - A constant list gives
0.0. - A second argument, a mean already known, is accepted, but the answer is the spread
about the data's own mean whatever is given, as in Python before 3.11. Leave it
out, or pass
null. - It is the square root of
stats.varianceexactly.
print(stats.stdev([7, 7, 7]), stats.stdev([1, 2], 1.5), stats.stdev([1, 2], null))print(stats.stdev([1, 2, 3, 4]) == math.sqrt(stats.variance([1, 2, 3, 4])))print(stats.stdev([1, 2, 3, 4]) == stats.describe([1, 2, 3, 4]).std)output
0.0 0.7071067811865476 0.7071067811865476truetrueErrors
Fewer than two numbers is a runtime error, not an error value: an empty list, null
or a list of one stops the request. So does an item that is not a number.
this one fails
print(stats.stdev([5]))output
line 1: `stats.stdev` requires at least 2 data pointsChaining
let xs = [2, 4, 4, 4, 5, 5, 7, 9]print(xs | stats.stdev | round(3))let m = stats.mean(xs)let s = stats.stdev(xs)print(xs | filter((x) => x > m + s))output
2.138[9]See also
stats.pstdev, stats.variance, stats.describe, stats.zscore
Thread
Thread 0 posts
On stats.stdev(): questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.
Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo