VOOZH about

URL: https://www.geeksforgeeks.org/python/special-functions-in-scipy/

⇱ Special functions in SciPy - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Special functions in SciPy

Last Updated : 4 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:

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

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]

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

Output

100.0

Example 2: Powers of 10 for a Range of Values

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:

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:

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:

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

Output

10.45862974442671

Example 2: With Two Lists

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:

Output

[4.0, 12.0, 24.0, 24.0, 0.0]

Related Articles:

Comment
Article Tags:
Article Tags: