Special functions (scipy.special
)¶
Nearly all of the functions below are universal functions and follow broadcasting and automatic array-looping rules. Exceptions are noted.
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 |
Bessel Functions¶
|
Bessel function of the first kind of real order and complex argument. |
|
Exponentially scaled Bessel function 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 |
The following is not an universal function:
|
Jahnke-Emden Lambda function, Lambdav(x). |
Zeros of Bessel Functions¶
These 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 function Jn(x). |
|
Compute zeros of integer-order Bessel function derivative Jn’(x). |
|
Compute zeros of integer-order Bessel function Yn(x). |
|
Compute zeros of integer-order Bessel function derivative 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 order 0 |
|
Integrals related to Bessel functions of order 0 |
|
Integrals of modified Bessel functions of order 0 |
|
Integrals related to modified Bessel functions of order 0 |
|
Weighted integral of a Bessel function. |
Derivatives of Bessel Functions¶
|
Compute nth derivative of Bessel function Jv(z) with respect to z. |
|
Compute nth derivative of Bessel function Yv(z) with respect to z. |
|
Compute nth derivative of real-order modified Bessel function Kv(z) |
|
Compute nth derivative of modified Bessel function Iv(z) with respect to z. |
|
Compute nth derivative of Hankel function H1v(z) with respect to z. |
|
Compute nth derivative 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¶
These 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 cumulative distribution function. |
|
Binomial distribution survival function. |
|
Inverse function to |
|
Inverse function to |
|
Inverse function to |
|
Cumulative density function of the beta distribution. |
|
The p-th quantile of the beta distribution. |
|
Inverse of |
|
Inverse of |
|
F cumulative distribution function. |
|
F survival function. |
|
The p-th quantile of the F-distribution. |
|
Inverse to |
|
Gamma distribution cumulative density function. |
|
Gamma distribution survival function. |
|
Inverse of |
|
Inverse of |
|
Inverse of |
|
Negative binomial cumulative distribution function. |
|
Negative binomial survival function. |
|
Inverse of |
|
Inverse of |
|
Inverse of |
|
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. |
|
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. |
|
Calculate mean of normal distribution given other params. |
|
Calculate standard deviation of normal distribution given other params. |
|
Poisson cumulative distribution function |
|
Poisson survival function |
|
Inverse to |
|
Inverse to |
|
Student t distribution cumulative density function |
|
Inverse of |
|
Inverse of |
|
Chi square cumulative distribution function |
|
Chi square survival function |
|
Inverse to |
|
Inverse to |
|
Gaussian cumulative distribution function. |
|
Logarithm of Gaussian cumulative distribution function. |
|
Inverse of |
|
Non-central chi square cumulative distribution function |
|
Inverse to |
|
Inverse to |
|
Inverse to |
|
Kolmogorov-Smirnov complementary cumulative distribution function |
|
Inverse to |
|
Complementary cumulative distribution (Survival Function) function of Kolmogorov distribution. |
|
Inverse Survival Function of Kolmogorov distribution |
|
Tukey-Lambda cumulative distribution function |
|
Logit ufunc for ndarrays. |
|
Expit (a.k.a. |
|
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. |
|
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 erf. |
|
Inverse of the complementary error function erfc. |
|
Faddeeva function |
|
Dawson’s integral. |
|
Fresnel sin and cos integrals |
|
Compute nt complex zeros of sine and cosine Fresnel integrals S(z) and C(z). |
|
Modified Fresnel positive integrals |
|
Modified Fresnel negative integrals |
These 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. |
These 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 (physicst’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(a, b; x) |
|
Confluent hypergeometric function U(a, b, x) of the second kind |
|
Confluent hypergeometric limit function 0F1. |
|
|
|
|
|
|
Parabolic Cylinder Functions¶
|
Parabolic cylinder function D |
|
Parabolic cylinder function V |
|
Parabolic cylinder function W. |
These 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 |
|
Derivative of the Kelvin function |
|
Kelvin function ker |
|
Kelvin function ker |
|
Derivative of the Kelvin function ker |
|
Derivative of the Kelvin function kei |
These are not universal functions:
|
Compute nt zeros of the Kelvin function ber(x). |
|
Compute nt zeros of the Kelvin function bei(x). |
|
Compute nt zeros of the Kelvin function ber’(x). |
|
Compute nt zeros of the Kelvin function bei’(x). |
|
Compute nt zeros of the Kelvin function ker(x). |
|
Compute nt zeros of the Kelvin function kei(x). |
|
Compute nt zeros of the Kelvin function ker’(x). |
|
Compute nt zeros of the Kelvin function kei’(x). |
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 |
|
Periodic sinc function, also called the Dirichlet function. |
|
Euler numbers E(0), E(1), …, E(n). |
|
Exponential integral E_n |
|
Exponential integral E_1 of complex argument z |
|
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. |
|
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 angle 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. |
|
Round to nearest integer |
|
Compute |
|
Compute |
|
Compute the log of the sum of exponentials of input elements. |
|
Relative error exponential, |
|
Return the sinc function. |