Reference · Statistics

stats.zscore

signature
stats.zscore(list | null) -> list

What it does

Each number of a list as a standard score: how many standard deviations it is from the list's mean, as a list of floats in the same order. The deviation is the population one (stats.pstdev), so a list's z-scores have mean 0 and deviation 1. It is not in Python's statistics module.

Examples

print(stats.zscore([1, 2, 3, 4, 5]))print(stats.zscore([72, 85, 90, 66, 85, 78]) | map((z) => round(z, 2)))
output
[-1.414213562373095, -0.7071067811865475, 0.0, 0.7071067811865475, 1.414213562373095][-0.89, 0.68, 1.29, -1.61, 0.68, -0.16]

Edge cases

print(stats.zscore([5, 5, 5]), stats.zscore([3]), stats.zscore([]), stats.zscore(null))print(stats.zscore([1, 2, 3, 100]) | map((z) => round(z, 3)))print(stats.zscore([2.5, 7.5]))
output
[0.0, 0.0, 0.0] [0.0] [] [][-0.601, -0.577, -0.554, 1.732][-1.0, 1.0]

Errors

An item that is not a number is a runtime error, not an error value. So is an argument that is not a list or null.

this one fails
print(stats.zscore([1, "x"]))
output
line 1: `stats.zscore` expects a list of numbers, but item 1 is str

Chaining

let scores = [72, 85, 90, 66, 85, 78]print(scores | stats.zscore | filter((z) => z > 1) | len)print(scores | stats.zscore | map((z) => round(z, 1)))
output
1[-0.9, 0.7, 1.3, -1.6, 0.7, -0.2]

See also

stats.normalize, stats.pstdev, stats.mean, stats.rank

Thread
7Useful? Like it, or add to its thread below.

Thread 0 posts

On stats.zscore(): 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