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.inf for 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:

  1. Take absolute value of each matrix element
  2. Sum each row
  3. Return the maximum row sum
Original Matrix: [-4, -3, -2] [-1, 0, 1] [ 2, 3, 4] Row Sums: |?4|+|?3|+|?2| = 9 |?1|+|0|+|1| = 2 |2|+|3|+|4| = 9 Max = 9.0

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.

---
Updated on: 2026-03-26T20:14:29+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements