
- SciPy - Home
- SciPy - Introduction
- SciPy - Environment Setup
- SciPy - Basic Functionality
- SciPy - Relationship with NumPy
- SciPy Clusters
- SciPy - Clusters
- SciPy - Hierarchical Clustering
- SciPy - K-means Clustering
- SciPy - Distance Metrics
- SciPy Constants
- SciPy - Constants
- SciPy - Mathematical Constants
- SciPy - Physical Constants
- SciPy - Unit Conversion
- SciPy - Astronomical Constants
- SciPy - Fourier Transforms
- SciPy - FFTpack
- SciPy - Discrete Fourier Transform (DFT)
- SciPy - Fast Fourier Transform (FFT)
- SciPy Integration Equations
- SciPy - Integrate Module
- SciPy - Single Integration
- SciPy - Double Integration
- SciPy - Triple Integration
- SciPy - Multiple Integration
- SciPy Differential Equations
- SciPy - Differential Equations
- SciPy - Integration of Stochastic Differential Equations
- SciPy - Integration of Ordinary Differential Equations
- SciPy - Discontinuous Functions
- SciPy - Oscillatory Functions
- SciPy - Partial Differential Equations
- SciPy Interpolation
- SciPy - Interpolate
- SciPy - Linear 1-D Interpolation
- SciPy - Polynomial 1-D Interpolation
- SciPy - Spline 1-D Interpolation
- SciPy - Grid Data Multi-Dimensional Interpolation
- SciPy - RBF Multi-Dimensional Interpolation
- SciPy - Polynomial & Spline Interpolation
- SciPy Curve Fitting
- SciPy - Curve Fitting
- SciPy - Linear Curve Fitting
- SciPy - Non-Linear Curve Fitting
- SciPy - Input & Output
- SciPy - Input & Output
- SciPy - Reading & Writing Files
- SciPy - Working with Different File Formats
- SciPy - Efficient Data Storage with HDF5
- SciPy - Data Serialization
- SciPy Linear Algebra
- SciPy - Linalg
- SciPy - Matrix Creation & Basic Operations
- SciPy - Matrix LU Decomposition
- SciPy - Matrix QU Decomposition
- SciPy - Singular Value Decomposition
- SciPy - Cholesky Decomposition
- SciPy - Solving Linear Systems
- SciPy - Eigenvalues & Eigenvectors
- SciPy Image Processing
- SciPy - Ndimage
- SciPy - Reading & Writing Images
- SciPy - Image Transformation
- SciPy - Filtering & Edge Detection
- SciPy - Top Hat Filters
- SciPy - Morphological Filters
- SciPy - Low Pass Filters
- SciPy - High Pass Filters
- SciPy - Bilateral Filter
- SciPy - Median Filter
- SciPy - Non - Linear Filters in Image Processing
- SciPy - High Boost Filter
- SciPy - Laplacian Filter
- SciPy - Morphological Operations
- SciPy - Image Segmentation
- SciPy - Thresholding in Image Segmentation
- SciPy - Region-Based Segmentation
- SciPy - Connected Component Labeling
- SciPy Optimize
- SciPy - Optimize
- SciPy - Special Matrices & Functions
- SciPy - Unconstrained Optimization
- SciPy - Constrained Optimization
- SciPy - Matrix Norms
- SciPy - Sparse Matrix
- SciPy - Frobenius Norm
- SciPy - Spectral Norm
- SciPy Condition Numbers
- SciPy - Condition Numbers
- SciPy - Linear Least Squares
- SciPy - Non-Linear Least Squares
- SciPy - Finding Roots of Scalar Functions
- SciPy - Finding Roots of Multivariate Functions
- SciPy - Signal Processing
- SciPy - Signal Filtering & Smoothing
- SciPy - Short-Time Fourier Transform
- SciPy - Wavelet Transform
- SciPy - Continuous Wavelet Transform
- SciPy - Discrete Wavelet Transform
- SciPy - Wavelet Packet Transform
- SciPy - Multi-Resolution Analysis
- SciPy - Stationary Wavelet Transform
- SciPy - Statistical Functions
- SciPy - Stats
- SciPy - Descriptive Statistics
- SciPy - Continuous Probability Distributions
- SciPy - Discrete Probability Distributions
- SciPy - Statistical Tests & Inference
- SciPy - Generating Random Samples
- SciPy - Kaplan-Meier Estimator Survival Analysis
- SciPy - Cox Proportional Hazards Model Survival Analysis
- SciPy Spatial Data
- SciPy - Spatial
- SciPy - Special Functions
- SciPy - Special Package
- SciPy Advanced Topics
- SciPy - CSGraph
- SciPy - ODR
- SciPy Useful Resources
- SciPy - Reference
- SciPy - Quick Guide
- SciPy - Cheatsheet
- SciPy - Useful Resources
- SciPy - Discussion
SciPy - Special Package
The functions available in the special package are universal functions, which follow broadcasting and automatic array looping.
Let us look at some of the most frequently used special functions −
- Cubic Root Function
- Exponential Function
- Relative Error Exponential Function
- Log Sum Exponential Function
- Lambert Function
- Permutations and Combinations Function
- Gamma Function
Let us now understand each of these functions in brief.
Cubic Root Function
The syntax of this cubic root function is scipy.special.cbrt(x). This will fetch the element-wise cube root of x.
Let us consider the following example.
from scipy.special import cbrt res = cbrt([10, 9, 0.1254, 234]) print res
The above program will generate the following output.
[ 2.15443469 2.08008382 0.50053277 6.16224015]
Exponential Function
The syntax of the exponential function is scipy.special.exp10(x). This will compute 10**x element wise.
Let us consider the following example.
from scipy.special import exp10 res = exp10([2, 9]) print res
The above program will generate the following output.
[1.00000000e+02 1.00000000e+09]
Relative Error Exponential Function
The syntax for this function is scipy.special.exprel(x). It generates the relative error exponential, (exp(x) - 1)/x.
When x is near zero, exp(x) is near 1, so the numerical calculation of exp(x) - 1 can suffer from catastrophic loss of precision. Then exprel(x) is implemented to avoid the loss of precision, which occurs when x is near zero.
Let us consider the following example.
from scipy.special import exprel res = exprel([-0.25, -0.1, 0, 0.1, 0.25]) print res
The above program will generate the following output.
[0.88479687 0.95162582 1. 1.05170918 1.13610167]
Log Sum Exponential Function
The syntax for this function is scipy.special.logsumexp(x). It helps to compute the log of the sum of exponentials of input elements.
Let us consider the following example.
from scipy.special import logsumexp import numpy as np a = np.arange(10) res = logsumexp(a) print res
The above program will generate the following output.
9.45862974443
Lambert Function
The syntax for this function is scipy.special.lambertw(x). It is also called as the Lambert W function. The Lambert W function W(z) is defined as the inverse function of w * exp(w). In other words, the value of W(z) is such that z = W(z) * exp(W(z)) for any complex number z.
The Lambert W function is a multivalued function with infinitely many branches. Each branch gives a separate solution of the equation z = w exp(w). Here, the branches are indexed by the integer k.
Let us consider the following example. Here, the Lambert W function is the inverse of w exp(w).
from scipy.special import lambertw w = lambertw(1) print w print w * np.exp(w)
The above program will generate the following output.
(0.56714329041+0j) (1+0j)
Permutations & Combinations
Let us discuss permutations and combinations separately for understanding them clearly.
Combinations − The syntax for combinations function is scipy.special.comb(N,k). Let us consider the following example −
from scipy.special import comb res = comb(10, 3, exact = False,repetition=True) print res
The above program will generate the following output.
220.0
Note − Array arguments are accepted only for exact = False case. If k > N, N < 0, or k < 0, then a 0 is returned.
Permutations − The syntax for combinations function is scipy.special.perm(N,k). Permutations of N things taken k at a time, i.e., k-permutations of N. This is also known as partial permutations.
Let us consider the following example.
from scipy.special import perm res = perm(10, 3, exact = True) print res
The above program will generate the following output.
720
Gamma Function
The gamma function is often referred to as the generalized factorial since z*gamma(z) = gamma(z+1) and gamma(n+1) = n!, for a natural number n.
The syntax for combinations function is scipy.special.gamma(x). Permutations of N things taken k at a time, i.e., k-permutations of N. This is also known as partial permutations.
The syntax for combinations function is scipy.special.gamma(x). Permutations of N things taken k at a time, i.e., k-permutations of N. This is also known as partial permutations.
from scipy.special import gamma res = gamma([0, 0.5, 1, 5]) print res
The above program will generate the following output.
[inf 1.77245385 1. 24.]