![]() |
VOOZH | about |
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:
Let's understand about these functions in detail.
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:
Output
4.0
4.272658681697917
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:
Example 1: Simple Combination
Output
4.0
Example 2: Multiple Combinations
Output
[4.0, 6.0, 4.0, 1.0, 0.0]
[6.0, 15.0, 20.0, 15.0, 6.0]
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
Output
100.0
Example 2: Powers of 10 for a Range of Values
Output
10.0
100.0
1000.0
10000.0
100000.0
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:
Output
1.0
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:
Output
1.2696403353658055e+73
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:
Output
(1.3267246652422002+0j)
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
Output
10.45862974442671
Example 2: With Two Lists
Output
10.45862974442671 15.456193316018123
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:
Example:
Output
[4.0, 12.0, 24.0, 24.0, 0.0]
Related Articles: