Distributions in Python
A frozen distribution answers pdf, cdf and ppf without repeating parameters.
import numpy as np
from scipy import stats
tpm = stats.norm(loc=95, scale=12)
print(round(tpm.pdf(95), 5), round(tpm.cdf(107), 4))
print(round(tpm.ppf(0.95), 2), tpm.interval(0.95)[0].round(2))
print(tpm.mean(), tpm.std(), round(tpm.var(), 1))
rng = np.random.default_rng(0)
print(tpm.rvs(size=4, random_state=rng).round(1))
How it works
norm(loc, scale)freezes the parameters into one object.cdfgoes value to probability,ppfgoes back.rvssamples, seeded by a Generator for reproducibility.
Keywords and builtins used here
asprintround
The run, in numbers
- Lines
- 11
- Characters to type
- 327
- Tokens
- 132
- Three-star pace
- 100 tpm
At the three-star pace of 100 tokens a minute, this run takes about 79 seconds.
Step 1 of 3 in Distributions, step 1 of 23 in Scientific computing with SciPy.