SciPy

Special functions (scipy.special)

Nearly all of the functions below are universal functions and follow broadcasting and automatic array-looping rules. Exceptions are noted.

Error handling

Errors are handled by returning nans, or other appropriate values. Some of the special function routines will emit warnings when an error occurs. By default this is disabled. To enable such messages use errprint(1), and to disable such messages use errprint(0).

Example:

>>> print scipy.special.bdtr(-1,10,0.3)
>>> scipy.special.errprint(1)
>>> print scipy.special.bdtr(-1,10,0.3)
errprint([inflag]) Sets or returns the error printing flag for special functions.
SpecialFunctionWarning Warning that can be issued with errprint(True)

Available functions

Airy functions

airy(z) Airy functions and their derivatives.
airye(z) Exponentially scaled Airy functions and their derivatives.
ai_zeros(nt) Compute nt zeros and values of the Airy function Ai and its derivative.
bi_zeros(nt) Compute nt zeros and values of the Airy function Bi and its derivative.
itairy(x) Integrals of Airy functions

Elliptic Functions and Integrals

ellipj(u, m) Jacobian elliptic functions
ellipk(m) Complete elliptic integral of the first kind.
ellipkm1(p) Complete elliptic integral of the first kind around m = 1
ellipkinc(phi, m) Incomplete elliptic integral of the first kind
ellipe(m) Complete elliptic integral of the second kind
ellipeinc(phi, m) Incomplete elliptic integral of the second kind

Bessel Functions

jv(v, z) Bessel function of the first kind of real order and complex argument.
jn(v, z) Bessel function of the first kind of real order and complex argument.
jve(v, z) Exponentially scaled Bessel function of order v.
yn(n, x) Bessel function of the second kind of integer order and real argument.
yv(v, z) Bessel function of the second kind of real order and complex argument.
yve(v, z) Exponentially scaled Bessel function of the second kind of real order.
kn(n, x) Modified Bessel function of the second kind of integer order n
kv(v, z) Modified Bessel function of the second kind of real order v
kve(v, z) Exponentially scaled modified Bessel function of the second kind.
iv(v, z) Modified Bessel function of the first kind of real order.
ive(v, z) Exponentially scaled modified Bessel function of the first kind
hankel1(v, z) Hankel function of the first kind
hankel1e(v, z) Exponentially scaled Hankel function of the first kind
hankel2(v, z) Hankel function of the second kind
hankel2e(v, z) Exponentially scaled Hankel function of the second kind

The following is not an universal function:

lmbda(v, x) Jahnke-Emden Lambda function, Lambdav(x).

Zeros of Bessel Functions

These are not universal functions:

jnjnp_zeros(nt) Compute zeros of integer-order Bessel functions Jn and Jn’.
jnyn_zeros(n, nt) Compute nt zeros of Bessel functions Jn(x), Jn’(x), Yn(x), and Yn’(x).
jn_zeros(n, nt) Compute zeros of integer-order Bessel function Jn(x).
jnp_zeros(n, nt) Compute zeros of integer-order Bessel function derivative Jn’(x).
yn_zeros(n, nt) Compute zeros of integer-order Bessel function Yn(x).
ynp_zeros(n, nt) Compute zeros of integer-order Bessel function derivative Yn’(x).
y0_zeros(nt[, complex]) Compute nt zeros of Bessel function Y0(z), and derivative at each zero.
y1_zeros(nt[, complex]) Compute nt zeros of Bessel function Y1(z), and derivative at each zero.
y1p_zeros(nt[, complex]) Compute nt zeros of Bessel derivative Y1’(z), and value at each zero.

Faster versions of common Bessel Functions

j0(x) Bessel function of the first kind of order 0.
j1(x) Bessel function of the first kind of order 1.
y0(x) Bessel function of the second kind of order 0.
y1(x) Bessel function of the second kind of order 1.
i0(x) Modified Bessel function of order 0.
i0e(x) Exponentially scaled modified Bessel function of order 0.
i1(x) Modified Bessel function of order 1.
i1e(x) Exponentially scaled modified Bessel function of order 1.
k0(x) Modified Bessel function of the second kind of order 0, \(K_0\).
k0e(x) Exponentially scaled modified Bessel function K of order 0
k1(x) Modified Bessel function of the second kind of order 1, \(K_1(x)\).
k1e(x) Exponentially scaled modified Bessel function K of order 1

Integrals of Bessel Functions

itj0y0(x) Integrals of Bessel functions of order 0
it2j0y0(x) Integrals related to Bessel functions of order 0
iti0k0(x) Integrals of modified Bessel functions of order 0
it2i0k0(x) Integrals related to modified Bessel functions of order 0
besselpoly(a, lmb, nu) Weighted integral of a Bessel function.

Derivatives of Bessel Functions

jvp(v, z[, n]) Compute nth derivative of Bessel function Jv(z) with respect to z.
yvp(v, z[, n]) Compute nth derivative of Bessel function Yv(z) with respect to z.
kvp(v, z[, n]) Compute nth derivative of real-order modified Bessel function Kv(z)
ivp(v, z[, n]) Compute nth derivative of modified Bessel function Iv(z) with respect to z.
h1vp(v, z[, n]) Compute nth derivative of Hankel function H1v(z) with respect to z.
h2vp(v, z[, n]) Compute nth derivative of Hankel function H2v(z) with respect to z.

Spherical Bessel Functions

spherical_jn(n, z[, derivative]) Spherical Bessel function of the first kind or its derivative.
spherical_yn(n, z[, derivative]) Spherical Bessel function of the second kind or its derivative.
spherical_in(n, z[, derivative]) Modified spherical Bessel function of the first kind or its derivative.
spherical_kn(n, z[, derivative]) Modified spherical Bessel function of the second kind or its derivative.

These are not universal functions:

sph_jn(*args, **kwds) sph_jn is deprecated!
sph_yn(*args, **kwds) sph_yn is deprecated!
sph_jnyn(*args, **kwds) sph_jnyn is deprecated!
sph_in(*args, **kwds) sph_in is deprecated!
sph_kn(*args, **kwds) sph_kn is deprecated!
sph_inkn(*args, **kwds) sph_inkn is deprecated!

Riccati-Bessel Functions

These are not universal functions:

riccati_jn(n, x) Compute Ricatti-Bessel function of the first kind and its derivative.
riccati_yn(n, x) Compute Ricatti-Bessel function of the second kind and its derivative.

Struve Functions

struve(v, x) Struve function.
modstruve(v, x) Modified Struve function.
itstruve0(x) Integral of the Struve function of order 0.
it2struve0(x) Integral related to the Struve function of order 0.
itmodstruve0(x) Integral of the modified Struve function of order 0.

Raw Statistical Functions

See also

scipy.stats: Friendly versions of these functions.

bdtr(k, n, p) Binomial distribution cumulative distribution function.
bdtrc(k, n, p) Binomial distribution survival function.
bdtri(k, n, y) Inverse function to bdtr with respect to p.
bdtrik(y, n, p) Inverse function to bdtr with respect to k.
bdtrin(k, y, p) Inverse function to bdtr with respect to n.
btdtr(a, b, x) Cumulative density function of the beta distribution.
btdtri(a, b, p) The p-th quantile of the beta distribution.
btdtria(p, b, x) Inverse of btdtr with respect to a.
btdtrib(a, p, x) Inverse of btdtr with respect to b.
fdtr(dfn, dfd, x) F cumulative distribution function.
fdtrc(dfn, dfd, x) F survival function.
fdtri(dfn, dfd, p) The p-th quantile of the F-distribution.
fdtridfd(dfn, p, x) Inverse to fdtr vs dfd
gdtr(a, b, x) Gamma distribution cumulative density function.
gdtrc(a, b, x) Gamma distribution survival function.
gdtria(p, b, x[, out]) Inverse of gdtr vs a.
gdtrib(a, p, x[, out]) Inverse of gdtr vs b.
gdtrix(a, b, p[, out]) Inverse of gdtr vs x.
nbdtr(k, n, p) Negative binomial cumulative distribution function.
nbdtrc(k, n, p) Negative binomial survival function.
nbdtri(k, n, y) Inverse of nbdtr vs p.
nbdtrik(y, n, p) Inverse of nbdtr vs k.
nbdtrin(k, y, p) Inverse of nbdtr vs n.
ncfdtr(dfn, dfd, nc, f) Cumulative distribution function of the non-central F distribution.
ncfdtridfd(p, f, dfn, nc) Calculate degrees of freedom (denominator) for the noncentral F-distribution.
ncfdtridfn(p, f, dfd, nc) Calculate degrees of freedom (numerator) for the noncentral F-distribution.
ncfdtri(p, dfn, dfd, nc) Inverse cumulative distribution function of the non-central F distribution.
ncfdtrinc(p, f, dfn, dfd) Calculate non-centrality parameter for non-central F distribution.
nctdtr(df, nc, t) Cumulative distribution function of the non-central t distribution.
nctdtridf(p, nc, t) Calculate degrees of freedom for non-central t distribution.
nctdtrit(df, nc, p) Inverse cumulative distribution function of the non-central t distribution.
nctdtrinc(df, p, t) Calculate non-centrality parameter for non-central t distribution.
nrdtrimn(p, x, std) Calculate mean of normal distribution given other params.
nrdtrisd(p, x, mn) Calculate standard deviation of normal distribution given other params.
pdtr(k, m) Poisson cumulative distribution function
pdtrc(k, m) Poisson survival function
pdtri(k, y) Inverse to pdtr vs m
pdtrik(p, m) Inverse to pdtr vs k
stdtr(df, t) Student t distribution cumulative density function
stdtridf(p, t) Inverse of stdtr vs df
stdtrit(df, p) Inverse of stdtr vs t
chdtr(v, x) Chi square cumulative distribution function
chdtrc(v, x) Chi square survival function
chdtri(v, p) Inverse to chdtrc
chdtriv(p, x) Inverse to chdtr vs v
ndtr(x) Gaussian cumulative distribution function.
log_ndtr(x) Logarithm of Gaussian cumulative distribution function.
ndtri(y) Inverse of ndtr vs x
chndtr(x, df, nc) Non-central chi square cumulative distribution function
chndtridf(x, p, nc) Inverse to chndtr vs df
chndtrinc(x, df, p) Inverse to chndtr vs nc
chndtrix(p, df, nc) Inverse to chndtr vs x
smirnov(n, e) Kolmogorov-Smirnov complementary cumulative distribution function
smirnovi(n, y) Inverse to smirnov
kolmogorov(y) Complementary cumulative distribution function of Kolmogorov distribution
kolmogi(p) Inverse function to kolmogorov
tklmbda(x, lmbda) Tukey-Lambda cumulative distribution function
logit(x) Logit ufunc for ndarrays.
expit(x) Expit ufunc for ndarrays.
boxcox(x, lmbda) Compute the Box-Cox transformation.
boxcox1p(x, lmbda) Compute the Box-Cox transformation of 1 + x.
inv_boxcox(y, lmbda) Compute the inverse of the Box-Cox transformation.
inv_boxcox1p(y, lmbda) Compute the inverse of the Box-Cox transformation.

Information Theory Functions

entr(x) Elementwise function for computing entropy.
rel_entr(x, y) Elementwise function for computing relative entropy.
kl_div(x, y) Elementwise function for computing Kullback-Leibler divergence.
huber(delta, r) Huber loss function.
pseudo_huber(delta, r) Pseudo-Huber loss function.

Error Function and Fresnel Integrals

erf(z) Returns the error function of complex argument.
erfc(x) Complementary error function, 1 - erf(x).
erfcx(x) Scaled complementary error function, exp(x**2) * erfc(x).
erfi(z) Imaginary error function, -i erf(i z).
erfinv(y) Inverse function for erf.
erfcinv(y) Inverse function for erfc.
wofz(z) Faddeeva function
dawsn(x) Dawson’s integral.
fresnel(z) Fresnel sin and cos integrals
fresnel_zeros(nt) Compute nt complex zeros of sine and cosine Fresnel integrals S(z) and C(z).
modfresnelp(x) Modified Fresnel positive integrals
modfresnelm(x) Modified Fresnel negative integrals

These are not universal functions:

erf_zeros(nt) Compute nt complex zeros of error function erf(z).
fresnelc_zeros(nt) Compute nt complex zeros of cosine Fresnel integral C(z).
fresnels_zeros(nt) Compute nt complex zeros of sine Fresnel integral S(z).

Legendre Functions

lpmv(m, v, x) Associated legendre function of integer order.
sph_harm(m, n, theta, phi) Compute spherical harmonics.

These are not universal functions:

clpmn(m, n, z[, type]) Associated Legendre function of the first kind, Pmn(z).
lpn(n, z) Legendre functions of the first kind, Pn(z).
lqn(n, z) Legendre functions of the second kind, Qn(z).
lpmn(m, n, z) Associated Legendre function of the first kind, Pmn(z).
lqmn(m, n, z) Associated Legendre function of the second kind, Qmn(z).

Ellipsoidal Harmonics

ellip_harm(h2, k2, n, p, s[, signm, signn]) Ellipsoidal harmonic functions E^p_n(l)
ellip_harm_2(h2, k2, n, p, s) Ellipsoidal harmonic functions F^p_n(l)
ellip_normal(h2, k2, n, p) Ellipsoidal harmonic normalization constants gamma^p_n

Orthogonal polynomials

The following functions evaluate values of orthogonal polynomials:

assoc_laguerre(x, n[, k]) Compute the generalized (associated) Laguerre polynomial of degree n and order k.
eval_legendre(n, x[, out]) Evaluate Legendre polynomial at a point.
eval_chebyt(n, x[, out]) Evaluate Chebyshev T polynomial at a point.
eval_chebyu(n, x[, out]) Evaluate Chebyshev U polynomial at a point.
eval_chebyc(n, x[, out]) Evaluate Chebyshev C polynomial at a point.
eval_chebys(n, x[, out]) Evaluate Chebyshev S polynomial at a point.
eval_jacobi(n, alpha, beta, x[, out]) Evaluate Jacobi polynomial at a point.
eval_laguerre(n, x[, out]) Evaluate Laguerre polynomial at a point.
eval_genlaguerre(n, alpha, x[, out]) Evaluate generalized Laguerre polynomial at a point.
eval_hermite(n, x[, out]) Evaluate Hermite polynomial at a point.
eval_hermitenorm(n, x[, out]) Evaluate normalized Hermite polynomial at a point.
eval_gegenbauer(n, alpha, x[, out]) Evaluate Gegenbauer polynomial at a point.
eval_sh_legendre(n, x[, out]) Evaluate shifted Legendre polynomial at a point.
eval_sh_chebyt(n, x[, out]) Evaluate shifted Chebyshev T polynomial at a point.
eval_sh_chebyu(n, x[, out]) Evaluate shifted Chebyshev U polynomial at a point.
eval_sh_jacobi(n, p, q, x[, out]) Evaluate shifted Jacobi polynomial at a point.

The functions below, in turn, return the polynomial coefficients in orthopoly1d objects, which function similarly as numpy.poly1d. The orthopoly1d class also has an attribute weights which returns the roots, weights, and total weights for the appropriate form of Gaussian quadrature. These are returned in an n x 3 array with roots in the first column, weights in the second column, and total weights in the final column. Note that orthopoly1d objects are converted to poly1d when doing arithmetic, and lose information of the original orthogonal polynomial.

legendre(n[, monic]) Legendre polynomial coefficients
chebyt(n[, monic]) Return nth order Chebyshev polynomial of first kind, Tn(x).
chebyu(n[, monic]) Return nth order Chebyshev polynomial of second kind, Un(x).
chebyc(n[, monic]) Return n-th order Chebyshev polynomial of first kind, \(C_n(x)\).
chebys(n[, monic]) Return nth order Chebyshev polynomial of second kind, \(S_n(x)\).
jacobi(n, alpha, beta[, monic]) Returns the nth order Jacobi polynomial, P^(alpha,beta)_n(x) orthogonal over [-1,1] with weighting function (1-x)**alpha (1+x)**beta with alpha,beta > -1.
laguerre(n[, monic]) Return the nth order Laguerre polynoimal, L_n(x), orthogonal over
genlaguerre(n, alpha[, monic]) Returns the nth order generalized (associated) Laguerre polynomial,
hermite(n[, monic]) Return the nth order Hermite polynomial, H_n(x), orthogonal over
hermitenorm(n[, monic]) Return the nth order normalized Hermite polynomial, He_n(x), orthogonal
gegenbauer(n, alpha[, monic]) Return the nth order Gegenbauer (ultraspherical) polynomial,
sh_legendre(n[, monic]) Returns the nth order shifted Legendre polynomial, P^*_n(x), orthogonal over [0,1] with weighting function 1.
sh_chebyt(n[, monic]) Return nth order shifted Chebyshev polynomial of first kind, Tn(x).
sh_chebyu(n[, monic]) Return nth order shifted Chebyshev polynomial of second kind, Un(x).
sh_jacobi(n, p, q[, monic]) Returns the nth order Jacobi polynomial, G_n(p,q,x) orthogonal over [0,1] with weighting function (1-x)**(p-q) (x)**(q-1) with p>q-1 and q > 0.

Warning

Computing values of high-order polynomials (around order > 20) using polynomial coefficients is numerically unstable. To evaluate polynomial values, the eval_* functions should be used instead.

Roots and weights for orthogonal polynomials

c_roots(n[, mu]) Gauss-Chebyshev (first kind) quadrature.
cg_roots(n, alpha[, mu]) Gauss-Gegenbauer quadrature.
h_roots(n[, mu]) Gauss-Hermite (physicst’s) quadrature.
he_roots(n[, mu]) Gauss-Hermite (statistician’s) quadrature.
j_roots(n, alpha, beta[, mu]) Gauss-Jacobi quadrature.
js_roots(n, p1, q1[, mu]) Gauss-Jacobi (shifted) quadrature.
l_roots(n[, mu]) Gauss-Laguerre quadrature.
la_roots(n, alpha[, mu]) Gauss-generalized Laguerre quadrature.
p_roots(n[, mu]) Gauss-Legendre quadrature.
ps_roots(n[, mu]) Gauss-Legendre (shifted) quadrature.
s_roots(n[, mu]) Gauss-Chebyshev (second kind) quadrature.
t_roots(n[, mu]) Gauss-Chebyshev (first kind) quadrature.
ts_roots(n[, mu]) Gauss-Chebyshev (first kind, shifted) quadrature.
u_roots(n[, mu]) Gauss-Chebyshev (second kind) quadrature.
us_roots(n[, mu]) Gauss-Chebyshev (second kind, shifted) quadrature.

Hypergeometric Functions

hyp2f1(a, b, c, z) Gauss hypergeometric function 2F1(a, b; c; z).
hyp1f1(a, b, x) Confluent hypergeometric function 1F1(a, b; x)
hyperu(a, b, x) Confluent hypergeometric function U(a, b, x) of the second kind
hyp0f1(v, x) Confluent hypergeometric limit function 0F1.
hyp2f0(a, b, x, type) Hypergeometric function 2F0 in y and an error estimate
hyp1f2(a, b, c, x) Hypergeometric function 1F2 and error estimate
hyp3f0(a, b, c, x) Hypergeometric function 3F0 in y and an error estimate

Parabolic Cylinder Functions

pbdv(v, x) Parabolic cylinder function D
pbvv(v, x) Parabolic cylinder function V
pbwa(a, x) Parabolic cylinder function W

These are not universal functions:

pbdv_seq(v, x) Parabolic cylinder functions Dv(x) and derivatives.
pbvv_seq(v, x) Parabolic cylinder functions Vv(x) and derivatives.
pbdn_seq(n, z) Parabolic cylinder functions Dn(z) and derivatives.

Spheroidal Wave Functions

pro_ang1(m, n, c, x) Prolate spheroidal angular function of the first kind and its derivative
pro_rad1(m, n, c, x) Prolate spheroidal radial function of the first kind and its derivative
pro_rad2(m, n, c, x) Prolate spheroidal radial function of the secon kind and its derivative
obl_ang1(m, n, c, x) Oblate spheroidal angular function of the first kind and its derivative
obl_rad1(m, n, c, x) Oblate spheroidal radial function of the first kind and its derivative
obl_rad2(m, n, c, x) Oblate spheroidal radial function of the second kind and its derivative.
pro_cv(m, n, c) Characteristic value of prolate spheroidal function
obl_cv(m, n, c) Characteristic value of oblate spheroidal function
pro_cv_seq(m, n, c) Characteristic values for prolate spheroidal wave functions.
obl_cv_seq(m, n, c) Characteristic values for oblate spheroidal wave functions.

The following functions require pre-computed characteristic value:

pro_ang1_cv(m, n, c, cv, x) Prolate spheroidal angular function pro_ang1 for precomputed characteristic value
pro_rad1_cv(m, n, c, cv, x) Prolate spheroidal radial function pro_rad1 for precomputed characteristic value
pro_rad2_cv(m, n, c, cv, x) Prolate spheroidal radial function pro_rad2 for precomputed characteristic value
obl_ang1_cv(m, n, c, cv, x) Oblate spheroidal angular function obl_ang1 for precomputed characteristic value
obl_rad1_cv(m, n, c, cv, x) Oblate spheroidal radial function obl_rad1 for precomputed characteristic value
obl_rad2_cv(m, n, c, cv, x) Oblate spheroidal radial function obl_rad2 for precomputed characteristic value

Kelvin Functions

kelvin(x) Kelvin functions as complex numbers
kelvin_zeros(nt) Compute nt zeros of all Kelvin functions.
ber(x) Kelvin function ber.
bei(x) Kelvin function bei
berp(x) Derivative of the Kelvin function ber
beip(x) Derivative of the Kelvin function bei
ker(x) Kelvin function ker
kei(x) Kelvin function ker
kerp(x) Derivative of the Kelvin function ker
keip(x) Derivative of the Kelvin function kei

These are not universal functions:

ber_zeros(nt) Compute nt zeros of the Kelvin function ber(x).
bei_zeros(nt) Compute nt zeros of the Kelvin function bei(x).
berp_zeros(nt) Compute nt zeros of the Kelvin function ber’(x).
beip_zeros(nt) Compute nt zeros of the Kelvin function bei’(x).
ker_zeros(nt) Compute nt zeros of the Kelvin function ker(x).
kei_zeros(nt) Compute nt zeros of the Kelvin function kei(x).
kerp_zeros(nt) Compute nt zeros of the Kelvin function ker’(x).
keip_zeros(nt) Compute nt zeros of the Kelvin function kei’(x).

Combinatorics

comb(N, k[, exact, repetition]) The number of combinations of N things taken k at a time.
perm(N, k[, exact]) Permutations of N things taken k at a time, i.e., k-permutations of N.

Other Special Functions

agm(a, b) Arithmetic, Geometric Mean.
bernoulli(n) Bernoulli numbers B0..Bn (inclusive).
binom(n, k) Binomial coefficient
diric(x, n) Periodic sinc function, also called the Dirichlet function.
euler(n) Euler numbers E0..En (inclusive).
expn(n, x) Exponential integral E_n
exp1(z) Exponential integral E_1 of complex argument z
expi(x) Exponential integral Ei
factorial(n[, exact]) The factorial of a number or array of numbers.
factorial2(n[, exact]) Double factorial.
factorialk(n, k[, exact]) Multifactorial of n of order k, n(!!...!).
shichi(x) Hyperbolic sine and cosine integrals
sici(x) Sine and cosine integrals
spence(z) Spence’s function, also known as the dilogarithm.
lambertw(z[, k, tol]) Lambert W function [R994].
zeta(x[, q, out]) Riemann zeta function.
zetac(x) Riemann zeta function minus 1.

Convenience Functions

cbrt(x) Cube root of x
exp10(x) 10**x
exp2(x) 2**x
radian(d, m, s) Convert from degrees to radians
cosdg(x) Cosine of the angle x given in degrees.
sindg(x) Sine of angle given in degrees
tandg(x) Tangent of angle x given in degrees.
cotdg(x) Cotangent of the angle x given in degrees.
log1p(x) Calculates log(1+x) for use when x is near zero
expm1(x) exp(x) - 1 for use when x is near zero.
cosm1(x) cos(x) - 1 for use when x is near zero.
round(x) Round to nearest integer
xlogy(x, y) Compute x*log(y) so that the result is 0 if x = 0.
xlog1py(x, y) Compute x*log1p(y) so that the result is 0 if x = 0.
exprel(x) Relative error exponential, (exp(x)-1)/x, for use when x is near zero.
sinc(x) Return the sinc function.