Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Lib/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
from collections import Counter, namedtuple, defaultdict

_SQRT2 = sqrt(2.0)
_SQRT2PI = sqrt(tau)
_random = random

## Exceptions ##############################################################
Expand Down Expand Up @@ -1257,11 +1258,11 @@ def samples(self, n, *, seed=None):

def pdf(self, x):
"Probability density function. P(x <= X < x+dx) / dx"
variance = self._sigma * self._sigma
if not variance:
sigma = self._sigma
if not sigma:
raise StatisticsError('pdf() not defined when sigma is zero')
diff = x - self._mu
return exp(diff * diff / (-2.0 * variance)) / sqrt(tau * variance)
z = (x - self._mu) / sigma
return exp(-0.5 * z * z) / (_SQRT2PI * sigma)

def cdf(self, x):
"Cumulative distribution function. P(X <= x)"
Expand Down
Loading