Special functions (scipy.special
)#
Almost all of the functions below accept NumPy arrays as input arguments as well as single numbers. This means they follow broadcasting and automatic array-looping rules. Technically, they are NumPy universal functions. Functions which do not accept NumPy arrays are marked by a warning in the section description.
See also
scipy.special.cython_special
– Typed Cython versions of special functions
Error handling#
Errors are handled by returning NaNs or other appropriate values. Some of the special function routines can emit warnings or raise exceptions when an error occurs. By default this is disabled; to query and control the current error handling state the following functions are provided.
Get the current way of handling special-function errors. |
|
Set how special-function errors are handled. |
|
|
Context manager for special-function error handling. |
Warning that can be emitted by special functions. |
|
Exception that can be raised by special functions. |
Available functions#
Airy functions#
|
Airy functions and their derivatives. |
|
Exponentially scaled Airy functions and their derivatives. |
|
Compute nt zeros and values of the Airy function Ai and its derivative. |
|
Compute nt zeros and values of the Airy function Bi and its derivative. |
|
Integrals of Airy functions |
Elliptic functions and integrals#
|
Jacobian elliptic functions |
|
Complete elliptic integral of the first kind. |
|
Complete elliptic integral of the first kind around m = 1 |
|
Incomplete elliptic integral of the first kind |
|
Complete elliptic integral of the second kind |
|
Incomplete elliptic integral of the second kind |
|
Degenerate symmetric elliptic integral. |
|
Symmetric elliptic integral of the second kind. |
|
Completely-symmetric elliptic integral of the first kind. |
|
Completely-symmetric elliptic integral of the second kind. |
|
Symmetric elliptic integral of the third kind. |
Bessel functions#
|
Bessel function of the first kind of real order and complex argument. |
|
Exponentially scaled Bessel function of the first kind of order v. |
|
Bessel function of the second kind of integer order and real argument. |
|
Bessel function of the second kind of real order and complex argument. |
|
Exponentially scaled Bessel function of the second kind of real order. |
|
Modified Bessel function of the second kind of integer order n |
|
Modified Bessel function of the second kind of real order v |
|
Exponentially scaled modified Bessel function of the second kind. |
|
Modified Bessel function of the first kind of real order. |
|
Exponentially scaled modified Bessel function of the first kind. |
|
Hankel function of the first kind |
|
Exponentially scaled Hankel function of the first kind |
|
Hankel function of the second kind |
|
Exponentially scaled Hankel function of the second kind |
|
Wright's generalized Bessel function. |
The following function does not accept NumPy arrays (it is not a universal function):
|
Jahnke-Emden Lambda function, Lambdav(x). |
Zeros of Bessel functions#
The following functions do not accept NumPy arrays (they are not universal functions):
|
Compute zeros of integer-order Bessel functions Jn and Jn'. |
|
Compute nt zeros of Bessel functions Jn(x), Jn'(x), Yn(x), and Yn'(x). |
|
Compute zeros of integer-order Bessel functions Jn. |
|
Compute zeros of integer-order Bessel function derivatives Jn'. |
|
Compute zeros of integer-order Bessel function Yn(x). |
|
Compute zeros of integer-order Bessel function derivatives Yn'(x). |
|
Compute nt zeros of Bessel function Y0(z), and derivative at each zero. |
|
Compute nt zeros of Bessel function Y1(z), and derivative at each zero. |
|
Compute nt zeros of Bessel derivative Y1'(z), and value at each zero. |
Faster versions of common Bessel functions#
|
Bessel function of the first kind of order 0. |
|
Bessel function of the first kind of order 1. |
|
Bessel function of the second kind of order 0. |
|
Bessel function of the second kind of order 1. |
|
Modified Bessel function of order 0. |
|
Exponentially scaled modified Bessel function of order 0. |
|
Modified Bessel function of order 1. |
|
Exponentially scaled modified Bessel function of order 1. |
|
Modified Bessel function of the second kind of order 0, \(K_0\). |
|
Exponentially scaled modified Bessel function K of order 0 |
|
Modified Bessel function of the second kind of order 1, \(K_1(x)\). |
|
Exponentially scaled modified Bessel function K of order 1 |
Integrals of Bessel functions#
|
Integrals of Bessel functions of the first kind of order 0. |
|
Integrals related to Bessel functions of the first kind of order 0. |
|
Integrals of modified Bessel functions of order 0. |
|
Integrals related to modified Bessel functions of order 0. |
|
Weighted integral of the Bessel function of the first kind. |
Derivatives of Bessel functions#
|
Compute derivatives of Bessel functions of the first kind. |
|
Compute derivatives of Bessel functions of the second kind. |
|
Compute derivatives of real-order modified Bessel function Kv(z) |
|
Compute derivatives of modified Bessel functions of the first kind. |
|
Compute derivatives of Hankel function H1v(z) with respect to z. |
|
Compute derivatives of Hankel function H2v(z) with respect to z. |
Spherical Bessel functions#
|
Spherical Bessel function of the first kind or its derivative. |
|
Spherical Bessel function of the second kind or its derivative. |
|
Modified spherical Bessel function of the first kind or its derivative. |
|
Modified spherical Bessel function of the second kind or its derivative. |
Riccati-Bessel functions#
The following functions do not accept NumPy arrays (they are not universal functions):
|
Compute Ricatti-Bessel function of the first kind and its derivative. |
|
Compute Ricatti-Bessel function of the second kind and its derivative. |
Struve functions#
|
Struve function. |
|
Modified Struve function. |
|
Integral of the Struve function of order 0. |
|
Integral related to the Struve function of order 0. |
|
Integral of the modified Struve function of order 0. |
Raw statistical functions#
See also
scipy.stats
: Friendly versions of these functions.
Binomial distribution#
|
Binomial distribution cumulative distribution function. |
|
Binomial distribution survival function. |
|
Inverse function to |
|
Inverse function to |
|
Inverse function to |
Beta distribution#
|
Cumulative distribution function of the beta distribution. |
|
The p-th quantile of the beta distribution. |
|
Inverse of |
|
Inverse of |
F distribution#
|
F cumulative distribution function. |
|
F survival function. |
|
The p-th quantile of the F-distribution. |
|
Inverse to |
Gamma distribution#
|
Gamma distribution cumulative distribution function. |
|
Gamma distribution survival function. |
|
Inverse of |
|
Inverse of |
|
Inverse of |
Negative binomial distribution#
|
Negative binomial cumulative distribution function. |
|
Negative binomial survival function. |
|
Returns the inverse with respect to the parameter p of y = nbdtr(k, n, p), the negative binomial cumulative distribution function. |
|
Negative binomial percentile function. |
|
Inverse of |
Noncentral F distribution#
|
Cumulative distribution function of the non-central F distribution. |
|
Calculate degrees of freedom (denominator) for the noncentral F-distribution. |
|
Calculate degrees of freedom (numerator) for the noncentral F-distribution. |
|
Inverse with respect to f of the CDF of the non-central F distribution. |
|
Calculate non-centrality parameter for non-central F distribution. |
Noncentral t distribution#
|
Cumulative distribution function of the non-central t distribution. |
|
Calculate degrees of freedom for non-central t distribution. |
|
Inverse cumulative distribution function of the non-central t distribution. |
|
Calculate non-centrality parameter for non-central t distribution. |
Normal distribution#
|
Calculate mean of normal distribution given other params. |
|
Calculate standard deviation of normal distribution given other params. |
|
Cumulative distribution of the standard normal distribution. |
|
Logarithm of Gaussian cumulative distribution function. |
|
Inverse of |
|
Inverse of |
Poisson distribution#
|
Poisson cumulative distribution function. |
|
Poisson survival function |
|
Inverse to |
|
Inverse to |
Student t distribution#
|
Student t distribution cumulative distribution function |
|
Inverse of |
|
The p-th quantile of the student t distribution. |
Chi square distribution#
|
Chi square cumulative distribution function. |
|
Chi square survival function. |
|
Inverse to |
|
Inverse to |
Non-central chi square distribution#
|
Non-central chi square cumulative distribution function |
|
Inverse to |
|
Inverse to |
|
Inverse to |
Kolmogorov distribution#
|
Kolmogorov-Smirnov complementary cumulative distribution function |
|
Inverse to |
|
Complementary cumulative distribution (Survival Function) function of Kolmogorov distribution. |
|
Inverse Survival Function of Kolmogorov distribution |
Box-Cox transformation#
|
Compute the Box-Cox transformation. |
|
Compute the Box-Cox transformation of 1 + x. |
|
Compute the inverse of the Box-Cox transformation. |
|
Compute the inverse of the Box-Cox transformation. |
Sigmoidal functions#
|
Logit ufunc for ndarrays. |
|
Expit (a.k.a. |
|
Logarithm of the logistic sigmoid function. |
Miscellaneous#
|
Cumulative distribution function of the Tukey lambda distribution. |
|
Owen's T Function. |
Information Theory functions#
|
Elementwise function for computing entropy. |
|
Elementwise function for computing relative entropy. |
|
Elementwise function for computing Kullback-Leibler divergence. |
|
Huber loss function. |
|
Pseudo-Huber loss function. |
Error function and Fresnel integrals#
|
Returns the error function of complex argument. |
|
Complementary error function, |
|
Scaled complementary error function, |
|
Imaginary error function, |
|
Inverse of the error function. |
|
Inverse of the complementary error function. |
|
Faddeeva function |
|
Dawson's integral. |
|
Fresnel integrals. |
|
Compute nt complex zeros of sine and cosine Fresnel integrals S(z) and C(z). |
|
Modified Fresnel positive integrals |
|
Modified Fresnel negative integrals |
|
Voigt profile. |
The following functions do not accept NumPy arrays (they are not universal functions):
|
Compute the first nt zero in the first quadrant, ordered by absolute value. |
|
Compute nt complex zeros of cosine Fresnel integral C(z). |
|
Compute nt complex zeros of sine Fresnel integral S(z). |
Legendre functions#
|
Associated Legendre function of integer order and real degree. |
|
Compute spherical harmonics. |
The following functions do not accept NumPy arrays (they are not universal functions):
|
Associated Legendre function of the first kind for complex arguments. |
|
Legendre function of the first kind. |
|
Legendre function of the second kind. |
|
Sequence of associated Legendre functions of the first kind. |
|
Sequence of associated Legendre functions of the second kind. |
Ellipsoidal harmonics#
|
Ellipsoidal harmonic functions E^p_n(l) |
|
Ellipsoidal harmonic functions F^p_n(l) |
|
Ellipsoidal harmonic normalization constants gamma^p_n |
Orthogonal polynomials#
The following functions evaluate values of orthogonal polynomials:
|
Compute the generalized (associated) Laguerre polynomial of degree n and order k. |
|
Evaluate Legendre polynomial at a point. |
|
Evaluate Chebyshev polynomial of the first kind at a point. |
|
Evaluate Chebyshev polynomial of the second kind at a point. |
|
Evaluate Chebyshev polynomial of the first kind on [-2, 2] at a point. |
|
Evaluate Chebyshev polynomial of the second kind on [-2, 2] at a point. |
|
Evaluate Jacobi polynomial at a point. |
|
Evaluate Laguerre polynomial at a point. |
|
Evaluate generalized Laguerre polynomial at a point. |
|
Evaluate physicist's Hermite polynomial at a point. |
|
Evaluate probabilist's (normalized) Hermite polynomial at a point. |
|
Evaluate Gegenbauer polynomial at a point. |
|
Evaluate shifted Legendre polynomial at a point. |
|
Evaluate shifted Chebyshev polynomial of the first kind at a point. |
|
Evaluate shifted Chebyshev polynomial of the second kind at a point. |
|
Evaluate shifted Jacobi polynomial at a point. |
The following functions compute roots and quadrature weights for orthogonal polynomials:
|
Gauss-Legendre quadrature. |
|
Gauss-Chebyshev (first kind) quadrature. |
|
Gauss-Chebyshev (second kind) quadrature. |
|
Gauss-Chebyshev (first kind) quadrature. |
|
Gauss-Chebyshev (second kind) quadrature. |
|
Gauss-Jacobi quadrature. |
|
Gauss-Laguerre quadrature. |
|
Gauss-generalized Laguerre quadrature. |
|
Gauss-Hermite (physicist's) quadrature. |
|
Gauss-Hermite (statistician's) quadrature. |
|
Gauss-Gegenbauer quadrature. |
|
Gauss-Legendre (shifted) quadrature. |
|
Gauss-Chebyshev (first kind, shifted) quadrature. |
|
Gauss-Chebyshev (second kind, shifted) quadrature. |
|
Gauss-Jacobi (shifted) quadrature. |
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 polynomial. |
|
Chebyshev polynomial of the first kind. |
|
Chebyshev polynomial of the second kind. |
|
Chebyshev polynomial of the first kind on \([-2, 2]\). |
|
Chebyshev polynomial of the second kind on \([-2, 2]\). |
|
Jacobi polynomial. |
|
Laguerre polynomial. |
|
Generalized (associated) Laguerre polynomial. |
|
Physicist's Hermite polynomial. |
|
Normalized (probabilist's) Hermite polynomial. |
|
Gegenbauer (ultraspherical) polynomial. |
|
Shifted Legendre polynomial. |
|
Shifted Chebyshev polynomial of the first kind. |
|
Shifted Chebyshev polynomial of the second kind. |
|
Shifted Jacobi polynomial. |
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.
Hypergeometric functions#
|
Gauss hypergeometric function 2F1(a, b; c; z) |
|
Confluent hypergeometric function 1F1. |
|
Confluent hypergeometric function U |
|
Confluent hypergeometric limit function 0F1. |
Parabolic cylinder functions#
|
Parabolic cylinder function D |
|
Parabolic cylinder function V |
|
Parabolic cylinder function W. |
The following functions do not accept NumPy arrays (they are not universal functions):
|
Parabolic cylinder functions Dv(x) and derivatives. |
|
Parabolic cylinder functions Vv(x) and derivatives. |
|
Parabolic cylinder functions Dn(z) and derivatives. |
Spheroidal wave functions#
|
Prolate spheroidal angular function of the first kind and its derivative |
|
Prolate spheroidal radial function of the first kind and its derivative |
|
Prolate spheroidal radial function of the second kind and its derivative |
|
Oblate spheroidal angular function of the first kind and its derivative |
|
Oblate spheroidal radial function of the first kind and its derivative |
|
Oblate spheroidal radial function of the second kind and its derivative. |
|
Characteristic value of prolate spheroidal function |
|
Characteristic value of oblate spheroidal function |
|
Characteristic values for prolate spheroidal wave functions. |
|
Characteristic values for oblate spheroidal wave functions. |
The following functions require pre-computed characteristic value:
|
Prolate spheroidal angular function pro_ang1 for precomputed characteristic value |
|
Prolate spheroidal radial function pro_rad1 for precomputed characteristic value |
|
Prolate spheroidal radial function pro_rad2 for precomputed characteristic value |
|
Oblate spheroidal angular function obl_ang1 for precomputed characteristic value |
|
Oblate spheroidal radial function obl_rad1 for precomputed characteristic value |
|
Oblate spheroidal radial function obl_rad2 for precomputed characteristic value |
Kelvin functions#
|
Kelvin functions as complex numbers |
|
Compute nt zeros of all Kelvin functions. |
|
Kelvin function ber. |
|
Kelvin function bei. |
|
Derivative of the Kelvin function ber. |
|
Derivative of the Kelvin function bei. |
|
Kelvin function ker. |
|
Kelvin function kei. |
|
Derivative of the Kelvin function ker. |
|
Derivative of the Kelvin function kei. |
The following functions do not accept NumPy arrays (they are not universal functions):
|
Compute nt zeros of the Kelvin function ber. |
|
Compute nt zeros of the Kelvin function bei. |
|
Compute nt zeros of the derivative of the Kelvin function ber. |
|
Compute nt zeros of the derivative of the Kelvin function bei. |
|
Compute nt zeros of the Kelvin function ker. |
|
Compute nt zeros of the Kelvin function kei. |
|
Compute nt zeros of the derivative of the Kelvin function ker. |
|
Compute nt zeros of the derivative of the Kelvin function kei. |
Combinatorics#
|
The number of combinations of N things taken k at a time. |
|
Permutations of N things taken k at a time, i.e., k-permutations of N. |
Other special functions#
|
Compute the arithmetic-geometric mean of a and b. |
|
Bernoulli numbers B0..Bn (inclusive). |
|
Binomial coefficient considered as a function of two real variables. |
|
Periodic sinc function, also called the Dirichlet function. |
|
Euler numbers E(0), E(1), ..., E(n). |
|
Generalized exponential integral En. |
|
Exponential integral E1. |
|
Exponential integral Ei. |
|
The factorial of a number or array of numbers. |
|
Double factorial. |
|
Multifactorial of n of order k, n(!!...!). |
|
Hyperbolic sine and cosine integrals. |
|
Sine and cosine integrals. |
|
Compute the softmax function. |
|
Compute the logarithm of the softmax function. |
|
Spence's function, also known as the dilogarithm. |
|
Riemann or Hurwitz zeta function. |
|
Riemann zeta function minus 1. |
Convenience functions#
|
Element-wise cube root of x. |
|
Compute |
|
Compute |
|
Convert from degrees to radians. |
|
Cosine of the angle x given in degrees. |
|
Sine of the angle x given in degrees. |
|
Tangent of angle x given in degrees. |
|
Cotangent of the angle x given in degrees. |
|
Calculates log(1 + x) for use when x is near zero. |
|
Compute |
|
cos(x) - 1 for use when x is near zero. |
|
Computes |
|
Round to the nearest integer. |
|
Compute |
|
Compute |
|
Compute the log of the sum of exponentials of input elements. |
|
Relative error exponential, |
|
Return the normalized sinc function. |