Special functions (scipy.special)#
Almost all of the functions below accept NumPy arrays as inputarguments as well as single numbers. This means they followbroadcasting and automatic array-looping rules. Technically,they areNumPy universal functions.Functions which do not accept NumPy arrays are marked by a warningin 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 raiseexceptions when an error occurs. By default this is disabled, exceptfor memory allocation errors, which result in an exception being raised.To query and control the current error handling state the followingfunctions are provided.
Available functions#
Airy functions#
| Airy functions and their derivatives. |
| Exponentially scaled Airy functions and their derivatives. |
| Computent zeros and values of the Airy function Ai and its derivative. |
| Computent zeros and values of the Airy function Bi and its derivative. |
| Integrals of Airy functions |
Elliptic functions and integrals#
| Jacobi elliptic functions |
| Complete elliptic integral of the first kind. |
| Complete elliptic integral of the first kind aroundm = 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 orderv. |
| 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 first kind of real order. |
| Exponentially scaled modified Bessel function of the first kind. |
| Modified Bessel function of the second kind of integer ordern |
| Modified Bessel function of the second kind of real orderv |
| Exponentially scaled modified Bessel function of the second 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. |
| Natural logarithm of Wright's generalized Bessel function, see |
The following function does not accept NumPy arrays (it is not auniversal function):
| Jahnke-Emden Lambda function, Lambdav(x). |
Zeros of Bessel functions#
The following functions do not accept NumPy arrays (they are notuniversal 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 modified Bessel functions of the first kind. |
| Compute derivatives of real-order modified Bessel function Kv(z) |
| Compute derivatives of Hankel function H1v(z) with respect toz. |
| Compute derivatives of Hankel function H2v(z) with respect toz. |
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 notuniversal functions):
| Compute Riccati-Bessel function of the first kind and its derivative. |
| Compute Riccati-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#
F distribution#
Gamma distribution#
Negative binomial distribution#
| Negative binomial cumulative distribution function. |
| Negative binomial survival function. |
| Returns the inverse with respect to the parameterp of |
| 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 tof 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-centralt 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#
Student t distribution#
Chi square distribution#
Non-central chi square distribution#
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#
Miscellaneous#
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. |
Gamma and related functions#
| gamma function. |
| Logarithm of the absolute value of the gamma function. |
| Principal branch of the logarithm of the gamma function. |
| Sign of the gamma function. |
| Regularized lower incomplete gamma function. |
| Inverse to the regularized lower incomplete gamma function. |
| Regularized upper incomplete gamma function. |
| Inverse of the regularized upper incomplete gamma function. |
| Beta function. |
| Natural logarithm of absolute value of beta function. |
| Regularized incomplete beta function. |
| Complement of the regularized incomplete beta function. |
| Inverse of the regularized incomplete beta function. |
| Inverse of the complemented regularized incomplete beta function. |
| The digamma function. |
| Reciprocal of the gamma function. |
| Polygamma functions. |
| Returns the log of multivariate gamma, also sometimes called the generalized gamma. |
| The digamma function. |
| Pochhammer symbol. |
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 notuniversal 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#
| Legendre polynomial of the first kind. |
| All Legendre polynomials of the first kind up to the specified degree |
| Associated Legendre polynomial of the first kind. |
| All associated Legendre polynomials of the first kind up to the specified degree |
| Spherical Legendre polynomial of the first kind. |
| All spherical Legendre polynomials of the first kind up to the specified degree |
| Spherical harmonics. |
| All spherical harmonics up to the specified degree |
The following functions are in the process of being deprecated in favor of the above,which provide a more flexible and consistent interface.
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 fororthogonal 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 inorthopoly1d objects, which function similarly asnumpy.poly1d.Theorthopoly1d class also has an attributeweights, which returnsthe roots, weights, and total weights for the appropriate form of Gaussianquadrature. These are returned in annx3 array with roots in the firstcolumn, weights in the second column, and total weights in the final column.Note thatorthopoly1d objects are converted topoly1d when doingarithmetic, 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 (aroundorder>20) usingpolynomial coefficients is numerically unstable. To evaluate polynomialvalues, theeval_* functions should be used instead.
Hypergeometric functions#
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 notuniversal functions):
Mathieu and related functions#
| Characteristic value of even Mathieu functions |
| Characteristic value of odd Mathieu functions |
The following functions do not accept NumPy arrays (they are notuniversal functions):
| Fourier coefficients for even Mathieu and modified Mathieu functions. |
| Fourier coefficients for odd Mathieu and modified Mathieu functions. |
The following return both function and first derivative:
| Even Mathieu function and its derivative |
| Odd Mathieu function and its derivative |
| Even modified Mathieu function of the first kind and its derivative |
| Even modified Mathieu function of the second kind and its derivative |
| Odd modified Mathieu function of the first kind and its derivative |
| Odd modified Mathieu function of the second kind and its derivative |
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 notuniversal 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#
Lambert W and related functions#
| Lambert W function. |
| Wright Omega function. |
Other special functions#
| Compute the arithmetic-geometric mean ofa andb. |
| Bernoulli numbers B0..Bn (inclusive). |
| Binomial coefficient considered as a function of two real variables. |
| Periodic sinc function, also called the Dirichlet kernel. |
| 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. |
| Compute the softplus function element-wise. |
Convenience functions#
| Element-wise cube root ofx. |
| Compute |
| Compute |
| Convert from degrees to radians. |
| Cosine of the anglex given in degrees. |
| Sine of the anglex given in degrees. |
| Tangent of anglex given in degrees. |
| Cotangent of the anglex given in degrees. |
| Calculates log(1 + x) for use whenx is near zero. |
| Compute |
| cos(x) - 1 for use whenx 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. |