Overview:
-
The norm of a square matrix describes the magnitude of the matrix.
-
Matrix norm is a function that combines all the values of a matrix to form a single positive real number that satisfies the following conditions.
-
|| A || >= 0 for any square matrix A
-
|| A || >= 0 if and only if the matrix A = 0
-
|| kA || = | k | || A || where k is a scalar
-
|| A + B || <= || A || + || B ||
-
|| AB || <= || A || || B ||
-
-
There are several matrix norms and each of them are calculated differently.
-
The parameter ord of the numpy.linalg.norm() function denotes which matrix norm needs to be calculated.
Types of matrix norms:
-
Frobenius norm or Euclidean norm: Returns the square root of the sum of the squares of the
all matrix elements. This is the default norm returned by the numpy.norm() function when ord = None.
-
The 1-norm: The 1-norm is calculated by taking the maximum of the sums of the matrix columns. Column sums are calculated using the absolute value of the column elements.
-
The -1-norm: The -1-norm is calculated by taking the minimum of the sums of the matrix columns. Column sums are calculated using the absolute value of the column elements.
-
The 2-norm: Conventionally refers to the Euclidean norm. However when ord = 2, numpy.linalg.norm() returns the maximum of the singular values of the diagonal matrix obtained through singular value decomposition.
-
The -2-norm: Returns the minimum of the singular values of the diagonal matrix obtained through singular value decomposition.
-
Nuclear norm: The Nuclear norm is provided by summing up the singular values obtained through singular value decomposition.
Example:
# Example Python program that finds the various matrix norms of a given # matrix using the function norm() of numpy.linalg module # Create a 2x2 square matrix a1[0][0] = -2 print("Square matrix:") # Frobenius norm / Euclidean norm # When ord = 1 # When ord = -1 # When ord = 2 # When ord = -2 # When ord=inf # When ord=-inf |
Output:
Square matrix: |