scipy.special provides gamma, beta, Bessel, error functions, and more—appear in statistics, physics, and ML loss formulas.
Frequently used
special.gamma,special.factorialspecial.erf— Gaussian CDF building blockspecial.softmax— stable softmax (also in scipy.special)- Link to
statsdistributions sharing same math
Example
import numpy as np
from scipy import special, stats
print('gamma(5):', special.gamma(5)) # 4! = 24
print('erf(0):', special.erf(0))
print('norm cdf via erf relation at 1:', stats.norm.cdf(1))
Important interview questions and answers
- Q: gamma vs factorial?
A: gamma(n) = (n−1)! for positive integers; extends factorial to reals. - Q: erf role?
A: Relates to normal distribution tail probabilities.
Self-check
- What is special.gamma(5) for integer argument?
- How does erf connect to normal cdf?
Tip: special.gamma(n) for integer n is (n−1)!—links combinatorics to stats distributions.
Interview prep
- gamma?
Extends factorial to reals—links to stats distributions.
- erf?
Error function—connected to normal cdf.