Skip to main content
`Ctrl`+`K`

# 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, except for memory allocation errors, which result in an exception being raised. To query and control the current error handling state the following functions are provided.

`geterr`() | Get the current way of handling special-function errors.
`seterr`(**kwargs) | Set how special-function errors are handled.
`errstate`(**kwargs) | Context manager for special-function error handling.
`SpecialFunctionWarning` | Warning that can be emitted by special functions.
`SpecialFunctionError` | Exception that can be raised by special functions.

## Available functions

### Airy functions

`airy` |
`airye` |
`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` |

### Elliptic functions and integrals

`ellipj` |
`ellipk` |
`ellipkm1` |
`ellipkinc` |
`ellipe` |
`ellipeinc` |
`elliprc` |
`elliprd` |
`elliprf` |
`elliprg` |
`elliprj` |

### Bessel functions

`jv` |
`jve` |
`yn` |
`yv` |
`yve` |
`iv` |
`ive` |
`kn` |
`kv` |
`kve` |
`hankel1` |
`hankel1e` |
`hankel2` |
`hankel2e` |
`wright_bessel` |
`log_wright_bessel` |

The following function does not accept NumPy arrays (it is not a universal function):

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

#### Zeros of Bessel functions

The following functions do not accept NumPy arrays (they 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 functions Jn.
`jnp_zeros`(n, nt) | Compute zeros of integer-order Bessel function derivatives Jn'.
`yn_zeros`(n, nt) | Compute zeros of integer-order Bessel function Yn(x).
`ynp_zeros`(n, nt) | Compute zeros of integer-order Bessel function derivatives 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` |
`j1` |
`y0` |
`y1` |
`i0` |
`i0e` |
`i1` |
`i1e` |
`k0` |
`k0e` |
`k1` |
`k1e` |

#### Integrals of Bessel functions

`itj0y0` |
`it2j0y0` |
`iti0k0` |
`it2i0k0` |
`besselpoly` |

#### Derivatives of Bessel functions

`jvp`(v, z[, n]) | Compute derivatives of Bessel functions of the first kind.
`yvp`(v, z[, n]) | Compute derivatives of Bessel functions of the second kind.
`ivp`(v, z[, n]) | Compute derivatives of modified Bessel functions of the first kind.
`kvp`(v, z[, n]) | Compute derivatives of real-order modified Bessel function Kv(z)
`h1vp`(v, z[, n]) | Compute derivatives of Hankel function H1v(z) with respect to z.
`h2vp`(v, z[, n]) | Compute derivatives 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.

#### Riccati-Bessel functions

The following functions do not accept NumPy arrays (they are not universal functions):

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

### Struve functions

`struve` |
`modstruve` |
`itstruve0` |
`it2struve0` |
`itmodstruve0` |

### Raw statistical functions

See also

`scipy.stats`: Friendly versions of these functions.

#### Binomial distribution

`bdtr` |
`bdtrc` |
`bdtri` |
`bdtrik` |
`bdtrin` |

#### Beta distribution

`btdtria` |
`btdtrib` |

#### F distribution

`fdtr` |
`fdtrc` |
`fdtri` |
`fdtridfd` |

#### Gamma distribution

`gdtr` |
`gdtrc` |
`gdtria` |
`gdtrib` |
`gdtrix` |

#### Negative binomial distribution

`nbdtr` |
`nbdtrc` |
`nbdtri` |
`nbdtrik` |
`nbdtrin` |

#### Noncentral F distribution

`ncfdtr` |
`ncfdtridfd` |
`ncfdtridfn` |
`ncfdtri` |
`ncfdtrinc` |

#### Noncentral t distribution

`nctdtr` |
`nctdtridf` |
`nctdtrit` |
`nctdtrinc` |

#### Normal distribution

`nrdtrimn` |
`nrdtrisd` |
`ndtr` |
`log_ndtr` |
`ndtri` |
`ndtri_exp` |

#### Poisson distribution

`pdtr` |
`pdtrc` |
`pdtri` |
`pdtrik` |

#### Student t distribution

`stdtr` |
`stdtridf` |
`stdtrit` |

#### Chi square distribution

`chdtr` |
`chdtrc` |
`chdtri` |
`chdtriv` |

#### Non-central chi square distribution

`chndtr` |
`chndtridf` |
`chndtrinc` |
`chndtrix` |

#### Kolmogorov distribution

`smirnov` |
`smirnovi` |
`kolmogorov` |
`kolmogi` |

#### Box-Cox transformation

`boxcox` |
`boxcox1p` |
`inv_boxcox` |
`inv_boxcox1p` |

#### Sigmoidal functions

`logit` |
`expit` |
`log_expit` |

#### Miscellaneous

`tklmbda` |
`owens_t` |

### Information Theory functions

`entr` |
`rel_entr` |
`kl_div` |
`huber` |
`pseudo_huber` |

### Gamma and related functions

`gamma` |
`gammaln` |
`loggamma` |
`gammasgn` |
`gammainc` |
`gammaincinv` |
`gammaincc` |
`gammainccinv` |
`beta` |
`betaln` |
`betainc` |
`betaincc` |
`betaincinv` |
`betainccinv` |
`psi` |
`rgamma` |
`polygamma`(n, x) | Polygamma functions.
`multigammaln`(a, d) | Returns the log of multivariate gamma, also sometimes called the generalized gamma.
`digamma` |
`poch` |

### Error function and Fresnel integrals

`erf` |
`erfc` |
`erfcx` |
`erfi` |
`erfinv` |
`erfcinv` |
`wofz` |
`dawsn` |
`fresnel` |
`fresnel_zeros`(nt) | Compute nt complex zeros of sine and cosine Fresnel integrals S(z) and C(z).
`modfresnelp` |
`modfresnelm` |
`voigt_profile` |

The following functions do not accept NumPy arrays (they are not universal functions):

`erf_zeros`(nt) | Compute the first nt zero in the first quadrant, ordered by absolute value.
`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

`legendre_p` |
`legendre_p_all` |
`assoc_legendre_p` |
`assoc_legendre_p_all` |
`sph_legendre_p` |
`sph_legendre_p_all` |
`sph_harm_y` |
`sph_harm_y_all` |

The following functions are in the process of being deprecated in favor of the above, which provide a more flexible and consistent interface.

`lpmv` |
`lqn`(n, z) | Legendre function of the second kind.
`lqmn`(m, n, z) | Sequence of associated Legendre functions of the second kind.

### 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` |
`eval_chebyt` |
`eval_chebyu` |
`eval_chebyc` |
`eval_chebys` |
`eval_jacobi` |
`eval_laguerre` |
`eval_genlaguerre` |
`eval_hermite` |
`eval_hermitenorm` |
`eval_gegenbauer` |
`eval_sh_legendre` |
`eval_sh_chebyt` |
`eval_sh_chebyu` |
`eval_sh_jacobi` |

The following functions compute roots and quadrature weights for orthogonal polynomials:

`roots_legendre`(n[, mu]) | Gauss-Legendre quadrature.
`roots_chebyt`(n[, mu]) | Gauss-Chebyshev (first kind) quadrature.
`roots_chebyu`(n[, mu]) | Gauss-Chebyshev (second kind) quadrature.
`roots_chebyc`(n[, mu]) | Gauss-Chebyshev (first kind) quadrature.
`roots_chebys`(n[, mu]) | Gauss-Chebyshev (second kind) quadrature.
`roots_jacobi`(n, alpha, beta[, mu]) | Gauss-Jacobi quadrature.
`roots_laguerre`(n[, mu]) | Gauss-Laguerre quadrature.
`roots_genlaguerre`(n, alpha[, mu]) | Gauss-generalized Laguerre quadrature.
`roots_hermite`(n[, mu]) | Gauss-Hermite (physicist's) quadrature.
`roots_hermitenorm`(n[, mu]) | Gauss-Hermite (statistician's) quadrature.
`roots_gegenbauer`(n, alpha[, mu]) | Gauss-Gegenbauer quadrature.
`roots_sh_legendre`(n[, mu]) | Gauss-Legendre (shifted) quadrature.
`roots_sh_chebyt`(n[, mu]) | Gauss-Chebyshev (first kind, shifted) quadrature.
`roots_sh_chebyu`(n[, mu]) | Gauss-Chebyshev (second kind, shifted) quadrature.
`roots_sh_jacobi`(n, p1, q1[, mu]) | 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`(n[, monic]) | Legendre polynomial.
`chebyt`(n[, monic]) | Chebyshev polynomial of the first kind.
`chebyu`(n[, monic]) | Chebyshev polynomial of the second kind.
`chebyc`(n[, monic]) | Chebyshev polynomial of the first kind on \([-2, 2]\).
`chebys`(n[, monic]) | Chebyshev polynomial of the second kind on \([-2, 2]\).
`jacobi`(n, alpha, beta[, monic]) | Jacobi polynomial.
`laguerre`(n[, monic]) | Laguerre polynomial.
`genlaguerre`(n, alpha[, monic]) | Generalized (associated) Laguerre polynomial.
`hermite`(n[, monic]) | Physicist's Hermite polynomial.
`hermitenorm`(n[, monic]) | Normalized (probabilist's) Hermite polynomial.
`gegenbauer`(n, alpha[, monic]) | Gegenbauer (ultraspherical) polynomial.
`sh_legendre`(n[, monic]) | Shifted Legendre polynomial.
`sh_chebyt`(n[, monic]) | Shifted Chebyshev polynomial of the first kind.
`sh_chebyu`(n[, monic]) | Shifted Chebyshev polynomial of the second kind.
`sh_jacobi`(n, p, q[, monic]) | 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

`hyp2f1` |
`hyp1f1` |
`hyperu` |
`hyp0f1` |

### Parabolic cylinder functions

`pbdv` |
`pbvv` |
`pbwa` |

The following functions do not accept NumPy arrays (they 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.

### Mathieu and related functions

`mathieu_a` |
`mathieu_b` |

The following functions do not accept NumPy arrays (they are not universal functions):

`mathieu_even_coef`(m, q) | Fourier coefficients for even Mathieu and modified Mathieu functions.
`mathieu_odd_coef`(m, q) | Fourier coefficients for odd Mathieu and modified Mathieu functions.

The following return both function and first derivative:

`mathieu_cem` |
`mathieu_sem` |
`mathieu_modcem1` |
`mathieu_modcem2` |
`mathieu_modsem1` |
`mathieu_modsem2` |

### Spheroidal wave functions

`pro_ang1` |
`pro_rad1` |
`pro_rad2` |
`obl_ang1` |
`obl_rad1` |
`obl_rad2` |
`pro_cv` |
`obl_cv` |
`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` |
`pro_rad1_cv` |
`pro_rad2_cv` |
`obl_ang1_cv` |
`obl_rad1_cv` |
`obl_rad2_cv` |

### Kelvin functions

`kelvin` |
`kelvin_zeros`(nt) | Compute nt zeros of all Kelvin functions.
`ber` |
`bei` |
`berp` |
`beip` |
`ker` |
`kei` |
`kerp` |
`keip` |

The following functions do not accept NumPy arrays (they are not universal functions):

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

### 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.
`stirling2`(N, K, *[, exact]) | Generate Stirling number(s) of the second kind.

### Lambert W and related functions

`lambertw`(z[, k, tol]) | Lambert W function.
`wrightomega` |

### Other special functions

`agm` |
`bernoulli`(n) | Bernoulli numbers B0..Bn (inclusive).
`binom` |
`diric`(x, n) | Periodic sinc function, also called the Dirichlet kernel.
`euler`(n) | Euler numbers E(0), E(1), ..., E(n).
`expn` |
`exp1` |
`expi` |
`factorial`(n[, exact, extend]) | The factorial of a number or array of numbers.
`factorial2`(n[, exact, extend]) | Double factorial.
`factorialk`(n, k[, exact, extend]) | Multifactorial of n of order k, n(!!...!).
`shichi` |
`sici` |
`softmax`(x[, axis]) | Compute the softmax function.
`log_softmax`(x[, axis]) | Compute the logarithm of the softmax function.
`spence` |
`zeta`(x[, q, out]) | Riemann or Hurwitz zeta function.
`zetac` |
`softplus`(x, **kwargs) | Compute the softplus function element-wise.

### Convenience functions

`cbrt` |
`exp10` |
`exp2` |
`radian` |
`cosdg` |
`sindg` |
`tandg` |
`cotdg` |
`log1p` |
`expm1` |
`cosm1` |
`powm1` |
`round` |
`xlogy` |
`xlog1py` |
`logsumexp`(a[, axis, b, keepdims, return_sign]) | Compute the log of the sum of exponentials of input elements.
`exprel` |
`sinc`(x) | Return the normalized sinc function.