Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Return the infinity Norm of the matrix in Linear Algebra in Python
The infinity norm of a matrix is the maximum row sum of absolute values. In NumPy, we use LA.norm() with np.inf parameter to calculate this norm in Linear Algebra operations.
Syntax
numpy.linalg.norm(x, ord=None, axis=None, keepdims=False)
Parameters
- x ? Input array (1-D or 2-D)
-
ord ? Order of the norm. Use
np.inffor infinity norm - axis ? Axis along which to compute the norm
- keepdims ? Whether to keep dimensions in the result
Example
Let's calculate the infinity norm of a 3×3 matrix ?
import numpy as np
from numpy import linalg as LA
# Create a matrix
arr = np.array([[-4, -3, -2],
[-1, 0, 1],
[ 2, 3, 4]])
print("Matrix:")
print(arr)
# Calculate infinity norm
infinity_norm = LA.norm(arr, np.inf)
print(f"\nInfinity Norm: {infinity_norm}")
# Manual verification: max row sum of absolute values
row_sums = [sum(abs(row)) for row in arr]
print(f"\nRow sums of absolute values: {row_sums}")
print(f"Maximum row sum: {max(row_sums)}")
Matrix: [[-4 -3 -2] [-1 0 1] [ 2 3 4]] Infinity Norm: 9.0 Row sums of absolute values: [9, 2, 9] Maximum row sum: 9
How It Works
The infinity norm calculation follows these steps:
- Take absolute value of each matrix element
- Sum each row
- Return the maximum row sum
Different Matrix Example
Let's try with a different matrix to see varying results ?
import numpy as np
from numpy import linalg as LA
# Create different matrices
matrices = [
np.array([[1, 2], [3, 4]]),
np.array([[5, -6, 1], [2, 0, -3]]),
np.array([[1]])
]
for i, matrix in enumerate(matrices, 1):
print(f"Matrix {i}:")
print(matrix)
print(f"Infinity Norm: {LA.norm(matrix, np.inf)}")
print()
Matrix 1: [[1 2] [3 4]] Infinity Norm: 7.0 Matrix 2: [[ 5 -6 1] [ 2 0 -3]] Infinity Norm: 12.0 Matrix 3: [[1]] Infinity Norm: 1.0
Conclusion
The infinity norm represents the maximum row sum of absolute values in a matrix. Use LA.norm(matrix, np.inf) to calculate it efficiently. This norm is useful in numerical analysis and matrix conditioning.
Advertisements
