Special functions in SciPy
Last Updated :
04 Jul, 2025
SciPy provides special mathematical functions through scipy.special module. These functions include advanced computations like gamma functions, Bessel functions, error functions, beta functions etc. that are commonly used in scientific, statistical and engineering applications.
Commonly used functions in scipy.special:
- cbrt : returns the cube root of a number.
- comb : calculates the number of combinations.
- exp10 : computes 10 raised to the power x.
- exprel : returns (exp(x) - 1) / x, useful in limiting cases.
- gamma : generalization of factorial: gamma (n + 1) = n! for natural numbers.
- lambertw : computes the Lambert W function, where W(z) . eW(z) = z
- logsumexp : returns the logarithm of the sum of exponentials useful for numerical stability.
- perm : calculates the number of permutations.
Let's understand about these functions in detail.
1. cbrt
cbrt() function computes cube root of a number or an array of numbers.
Syntax:
scipy.special.cbrt(x)
Parameter: x is a single number or a list/array.
Example:
Python
from scipy.special import cbrt
print(cbrt(64))
print(cbrt(78))
Output
4.0
4.272658681697917
2. comb
comb() function calculates number of combinations, i.e., how many ways you can choose k items from N without regard to order.
Syntax:
scipy.special.comb(N, k)
Parameter:
- N: total number of items
- k: number of items to choose
Example 1: Simple Combination
Python
from scipy.special import comb
print(comb(4, 1))
Output
4.0
Example 2: Multiple Combinations
Python
from scipy.special import comb
# combinations of 4
print([comb(4,1),comb(4,2),comb(4,3),comb(4,4),comb(4,5)])
# combinations of 6
print([comb(6,1),comb(6,2),comb(6,3),comb(6,4),comb(6,5)])
Output
[4.0, 6.0, 4.0, 1.0, 0.0]
[6.0, 15.0, 20.0, 15.0, 6.0]
3. exp10()
exp10() function computes 10 raised to the power of the given input. It is equivalent to writing 10 ** x.
Syntax:
scipy.special.exp10(x)
Parameter: x is a exponent value (a number or array)
Example 1: Power of 10 for a Single Number
Python
from scipy.special import exp10
print(exp10(2))
Output
100.0
Example 2: Powers of 10 for a Range of Values
Python
from scipy.special import exp10
for i in range(1, 6):
print(exp10(i))
Output
10.0
100.0
1000.0
10000.0
100000.0
4. exprel()
exprel() function calculates exponential result used when input is close to zero. It helps avoid small calculation errors that can occur when using the standard exponential function (exp) near zero.
Syntax:
scipy.special.exprel(x)
Parameter: x is a input number (a single value or a list/array)
Example:
Python
from scipy.special import exprel
print(exprel(0))
Output
1.0
5. gamma()
gamma() function is a generalization of the factorial function. For natural numbers, it behaves like a factorial:
gamma(n+1) = n!
Syntax:
scipy.special.gamma(x)
Parameter: x is a input value (a number or list of numbers)
Example:
Python
from scipy.special import gamma
print(gamma(56))
Output
1.2696403353658055e+73
6. lambertw()
lambertw() function solve equations where variable appears both in the base and in the exponent. It is used when dealing with exponential and logarithmic expressions.
Syntax:
scipy.special.lambertw(x)
Parameter: x is a input value (real or complex)
Example:
Python
from scipy.special import lambertw
print(lambertw(5))
Output
(1.3267246652422002+0j)
7. logsumexp()
logsumexp() function compute logarithm of the sum of exponentials of input values. Used in numerical computations to maintain stability when working with very large or very small numbers.
Syntax:
scipy.special.logsumexp(x)
Parameter: x is a input list, array, or iterable of numbers
Example 1: Basic Usage
Python
from scipy.special import logsumexp
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print(logsumexp(a))
Output
10.45862974442671
Example 2: With Two Lists
Python
from scipy.special import logsumexp
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
b = [10, 11, 12, 13, 14, 15]
print(logsumexp(a), logsumexp(b))
Output
10.45862974442671 15.456193316018123
8. perm()
perm() function calculates number of permutations of k items chosen from N items. It consider order of selection.
Syntax:
scipy.special.perm(N, k)
Parameter:
- N: total number of items
- k: number of items to arrange (must be ≤ N)
Example:
Python
from scipy.special import perm
print([perm(4, 1), perm(4, 2), perm(4, 3), perm(4, 4), perm(4, 5)])
Output
[4.0, 12.0, 24.0, 24.0, 0.0]
Related Articles:
Similar Reads
numpy.sctype2char() function â Python numpy.sctype2char() function return the string representation of a scalar dtype. Syntax : numpy.sctype2char(sctype) Parameters : sctype : [scalar dtype or object] If a sctype is a scalar dtype, the corresponding string character is returned. If an object, sctype2char tries to infer its scalar type a
1 min read
SciPy stats.describe() Function scipy.stats.describe() function compute a variety of descriptive statistics for a dataset, including count, min/max, mean, variance, skewness and kurtosis. It's a convenient one-stop summary tool for numerical data analysis.Example:Pythonfrom scipy.stats import describe import numpy as np d = [4, 8,
2 min read
scipy stats.normaltest() function | Python scipy.stats.normaltest(array, axis=0) function test whether the sample is different from the normal distribution. This function tests the null hypothesis of the population that the sample was drawn from. Parameters : array : Input array or object having the elements. axis : Axis along which the norm
1 min read
numpy.typename() function â Python numpy.typename() function return a description for the given data type code. Syntax : numpy.typename(char) Parameters : char : [str] Data type code. Return : [str] Description of the input data type code. Code #1 : Python3 # Python program explaining # numpy.typename() function # importing numpy as
2 min read
sympy.stats.variance() function in Python In mathematics, the variance is the way to check the difference between the actual value and any random input, i.e variance can be calculated as a squared difference of these two values. With the help of sympy.stats.variance() method, we can calculate the value of variance by using this method. Synt
1 min read
numpy.roots() function - Python numpy.roots() function return the roots of a polynomial with coefficients given in p. The values in the rank-1 array p are coefficients of a polynomial. If the length of p is n+1 then the polynomial is described by: p[0] * x**n + p[1] * x**(n-1) + ... + p[n-1]*x + p[n] Syntax : numpy.roots(p) Parame
1 min read