diff options
| author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2020-04-16 10:25:14 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-16 10:25:14 -0700 |
| commit | 70f027dd22d6522b777d10c250f951e5e416b93a (patch) | |
| tree | b0208da206e983459af5eb714dc38ed026c51153 /Lib/statistics.py | |
| parent | 518835f3354d6672e61c9f52348c1e4a2533ea00 (diff) | |
| download | cpython-git-70f027dd22d6522b777d10c250f951e5e416b93a.tar.gz | |
bpo-40290: Add zscore() to statistics.NormalDist. (GH-19547)
Diffstat (limited to 'Lib/statistics.py')
| -rw-r--r-- | Lib/statistics.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/statistics.py b/Lib/statistics.py index 1e95c0b663..9beafb341b 100644 --- a/Lib/statistics.py +++ b/Lib/statistics.py @@ -999,6 +999,17 @@ class NormalDist: x2 = (a - b) / dv return 1.0 - (fabs(Y.cdf(x1) - X.cdf(x1)) + fabs(Y.cdf(x2) - X.cdf(x2))) + def zscore(self, x): + """Compute the Standard Score. (x - mean) / stdev + + Describes *x* in terms of the number of standard deviations + above or below the mean of the normal distribution. + """ + # https://www.statisticshowto.com/probability-and-statistics/z-score/ + if not self._sigma: + raise StatisticsError('zscore() not defined when sigma is zero') + return (x - self._mu) / self._sigma + @property def mean(self): "Arithmetic mean of the normal distribution." |
