
- 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 - L2 Norm(Spectral Norm)
Spectral Norm in SciPy (L2)
The L2 Norm (also known as the spectral norm) in SciPy is a matrix norm that corresponds to the largest singular value of the matrix. It is widely used in various fields such as numerical optimization, machine learning, and stability analysis due to its significance in measuring the largest scaling factor that the matrix can apply to any vector.
The L2 norm of a matrix A quantifies the maximum amount by which the matrix stretches a vector. In essence, it provides a measure of how much the matrix "expands" vectors in its domain. The norm is equal to the largest singular value of A, which can be found by computing the singular value decomposition (SVD) of the matrix.
If a matrix A has dimensions m x n, the mathematical formula for the L2 Norm (Spectral Norm) ||A||2 is:
$\mathrm{|A|_2 = σ^{max}}$
Where −
- σmax denotes the largest singular value of matrix A.
- The spectral norm is the largest eigenvalue of the matrix ATA where AT is the transpose of A.
Properties of the L2 Norm (Spectral Norm)
The L2 norm has a number of useful mathematical properties that make it important in many applications, especially in numerical analysis. These are some key properties −
Non-Negativity
The L2 norm is always non-negative and it is zero if and only if the matrix is a zero matrix i.e., all elements of A are zero.
A2 0
Homogeneity (Scaling)
The L2 norm is homogeneous with respect to scalar multiplication. That is, scaling a matrix by a constant factor scales its norm by the absolute value of the constant.
cA2 = |c| A2
where c is a scalar, and A is a matrix. This means that multiplying a matrix by a constant factor scales its L2 norm by the absolute value of that constant.
Subadditivity (Triangle Inequality)
The L2 norm satisfies the triangle inequality which means the norm of the sum of two matrices is less than or equal to the sum of their norms.
A + B2 A2 + B2
for matrices A and B of the same size. This property ensures that the L2 norm behaves like a distance metric.
Invariance under Orthogonal/Unitary Transformations
The L2 norm remains unchanged when the matrix is multiplied by an orthogonal (real) or unitary (complex) matrix.
UA2 = A2 and AV2 = A2
where U and V are orthogonal or unitary matrices. This property is significant in many numerical methods such as Singular Value Decomposition (SVD) where transformations do not alter the L2 norm.
Example 1
The following example demonstrates how to compute the L2 Norm (Spectral Norm) using SciPy's scipy.linalg.norm() function by passing the argument ord=2. We can calculate the L2 Norm for a small 2D matrix −
import numpy as np from scipy.linalg import norm # Define the matrix A = np.array([[1, 2], [3, 4]]) # Compute the L2 norm (spectral norm) l2_norm = norm(A, ord=2) print("Matrix A:") print(A) print("L2 Norm (Spectral Norm) of A:", l2_norm)
Following is the output for the 2D matrix's L2 Norm −
Matrix A: [[1 2] [3 4]] L2 Norm (Spectral Norm) of A: 5.464985704219043
Example 2
In this example we calculate the L2 Norm or Spectral Norm for a complex matrix using the scipy.linalg.norm() function −
import numpy as np from scipy.linalg import norm # Define the complex matrix A = np.array([[1 + 1j, 2 - 1j], [-1j, 3 + 2j]]) # Compute the L2 norm (spectral norm) l2_norm = norm(A, ord=2) print("Complex Matrix A:") print(A) print("L2 Norm (Spectral Norm) of A:", l2_norm)
Heres the result of the L2 Norm (Spectral Norm) for a complex matrix −
Complex Matrix A: [[ 1.+1.j 2.-1.j] [-0.-1.j 3.+2.j]] L2 Norm (Spectral Norm) of A: 4.25045561972017
Example 3
Here in this example let's calculate the L2 Norm (Spectral Norm) for a zero matrix −
import numpy as np from scipy.linalg import norm # Define the zero matrix A = np.zeros((2, 2)) # Compute the L2 norm (spectral norm) l2_norm = norm(A, ord=2) print("Zero Matrix A:") print(A) print("L2 Norm (Spectral Norm) of A:", l2_norm)
Here is the output for the L2 Norm (Spectral Norm) of a zero matrix −
Zero Matrix A: [[0. 0.] [0. 0.]] L2 Norm (Spectral Norm) of A: 0.0