
- 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 - det()Function
The determinant of a square matrix A is computed with the scipy.linalg.det() function, which returns a scalar number that encompasses the most important properties of the matrix. It is suited for both small and large matrices because it performs LU decomposition to compute the determinant in an efficient way.
The determinant is used to find out whether a matrix is invertible (det0), whether rows or columns are linearly dependent, and the scaling transformations. It is also widely used in stability analysis, eigenvalue problems, and linear system solutions.
A singular matrix is non-invertible since its determinant is always 0. The determinant for any size identity matrix is 1. The determinants of complex number matrices include both real and imaginary components. The determinants of unitary or orthogonal matrices are either +1 or -1.
Syntax
Following is the syntax of the SciPy det() method −
.det(a, overwrite_a=False, check_finite=True)
Parameters
This method accepts the following parameters −
a (array_like) − A square matrix whose determinant is to be calculated.
overwrite_a (bool, optional) − If True, the input matrix a may be overwritten during the computation for better performance. Default is False.
check_finite (bool, optional) − If True, it checks that the input matrix contains only finite numbers. Performance could be better if False, but invalid inputs - such as NaNs or infinities - might lead to unexpected behavior. True is the default.
Return Value
det: (float or complex) The determinant of the matrix a.
Example 1
The determinant of an identity matrix is always 1, because every diagonal item contributes to the product by 1 and every off-diagonal entry is 0.
In the code below we have created a 44 identity matrix and let's compute the determinant of A using det() method. Following is the code −
import numpy as np import scipy.linalg from scipy.linalg import det A = np.eye(4) # 4x4 Identity matrix result = scipy.linalg.det(A) print(result)
When we run the above program, it produces the following result
1.0
Example 2
In the below code we have created a 2x2 matrix with fractional values and we will use the det() function to compute the determinant of A..
import numpy as np from scipy.linalg import det A = np.array([[0.5, 1.2], [3.4, 2.1]]) result = det(A) print(result)
Following is an output of the above code
-3.03
Example 3
A matrix with complex numbers is multi-dimensional in complex space, its determinant also consists of the real and imaginary parts.
In the below code we have created a 2x2 matrix with complex numbers and we will use det() function to calculate the det of A.
import numpy as np from scipy.linalg import det A = np.array([[2+3j, 4-1j], [1+2j, 3+4j]]) result = det(A) print(result)
Output of the above code is as follows
(-12+9.999999999999998j)
Example 4
The determinant has properties such as matrix invertibility and rank deficiency with det=0 for singular matrices and if the det is 0 the matrix is non- invertible.
This example computes the determinant of a matrix to check for singularity.
import numpy as np from scipy.linalg import det # Define a singular matrix (det = 0) A = np.array([[1, 2], [2, 4]]) determinant = det(A) if determinant == 0: print("Matrix is singular (non-invertible).") else: print("Matrix is invertible.")
Output of the above code is as follows
Matrix is singular (non-invertible).