Distributions
Normal PDF at a Point
Evaluate the Gaussian density f(x) = (1/(σ√(2π))) × exp(−½z²) where
z=(x−μ)/σ. Four named pieces: z (the standardized value), coeff
(1/(σ√(2π))), exp_term (exp(−½z²)), and their product pdf. At x=1, μ=0,
σ=1 (standard normal) the density is ≈0.241971. Library:
scipy.stats.norm.pdf(x, mu, sigma).
By hand
With the library
scipy.stats.norm.pdf(x, loc, scale) takes the point x first, then loc
(mean μ) and scale (std σ). Returns the density value — the same formula
evaluated at full floating-point precision.
naive.py
import math
x = 1
mu = 0
sigma = 1
z = (x - mu) / sigma
coeff = 1 / (sigma * math.sqrt(2 * math.pi))
exp_term = math.exp(-0.5 * z ** 2)
pdf = coeff * exp_term
print('RESULT:', round(pdf, 6))
library.py
from scipy.stats import norm
from dalib.display import set_display
set_display()
x = 1
mu = 0
sigma = 1
pdf = norm.pdf(x, mu, sigma)
print('x:', x, ' mu:', mu, ' sigma:', sigma)
print('RESULT:', round(pdf, 6))
x: 1 mu: 0 sigma: 1
RESULT: 0.241971
Implementation notes
- The pdf gives a density, not a probability. f(x) can exceed 1 for narrow distributions (small σ). The probability of falling in an interval [a, b] is the integral of f, not f itself.
- At x=μ the density is maximized: coeff = 1/(σ√(2π)), exp_term = 1 (since z=0). Density decreases symmetrically as |x−μ| grows.
- Cross-reference:
z-scores(ch02) for the standardization z=(x−μ)/σ that appears in the exponent;discrete-cdf(this chapter) for the analogous cumulative form.