Singular Value Decomposition
The Singular-Value Decomposition is a matrix decomposition method for reducing a matrix to its constituent parts to make specific subsequent matrix calculations simpler. It is calculated using scipy.linalg.svd.
Syntax: scipy.linalg.svd(a , full_matrices , compute_uv , overwrite_a , check_finite , lapack_driver)
Parameters:
- a: The input matrix.
- full_matrices (Optional): If True, the two decomposed unitary matrices of the input matrix are of shape (M, M), (N, N).
- compute_uv (Optional): The default value is True.
- overwrite_a (Optional): It grants permission to overwrite data in a.
- check_finite (Optional): It checks if the input matrix consists of only finite numbers.
- lapack_driver (Optional): It takes either the divide-and-conquer approach (‘gesdd’) or general rectangular approach (‘gesvd’).
The function scipy.linalg.svd takes a matrix M to decompose and returns:
- A Unitary matrix having left singular vectors as columns.
- The singular values sorted in non-increasing order.
- A unitary matrix having right singular vectors as rows.
Example:
Python
# Importing the required libraries from scipy import linalg import numpy as np # Initializing the matrix M M = np.array([[ 1 , 5 ] , [ 6 , 10 ]]) # Passing the values to the # eigen function x , y , z = linalg.svd(M) print (x , y , z) |
Output:
SciPy Linear Algebra – SciPy Linalg
The SciPy package includes the features of the NumPy package in Python. It uses NumPy arrays as the fundamental data structure. It has all the features included in the linear algebra of the NumPy module and some extended functionality. It consists of a linalg submodule, and there is an overlap in the functionality provided by the SciPy and NumPy submodules.
Let’s discuss some methods provided by the module and its functionality with some examples.