Calculating the norm

To define how close two vectors or matrices are, and to define the convergence of sequences of vectors or matrices, the norm is used. The function scipy.linalg.norm is used to calculate the matrix or vector norm.

Syntax: scipy.linalg.norm(a , ord , axis , keepdims , check_finite)

Parameters:

  • a: It is an input array or matrix.
  • ord (Optional): It is the order of the norm
  • axis (Optional): It denotes the axes.
  • keepdims (Optional): If the value is True, the axes which are normed over are left in the output as dimensions with size=1.
  • check_finite (Optional): It checks if the input matrix consists of only finite numbers.

Returns:

  • scipy.linalg.norm returns the norm of a.

The function scipy.linalg.norm returns one of the seven different matrix norms or one of an infinite number of vector norms. 

  1. The L2 norm evaluates the distance of the vector coordinate from the origin of the vector space. It is also known as the Euclidean norm as it is calculated as the Euclidean distance from the origin. The result is a positive distance value.
  2. The L1 norm is evaluated as the sum of the absolute vector values. It is an evaluation of the Manhattan distance from the origin of the vector space.

Example:

Python




# Importing the required libraries
from scipy import linalg
import numpy as np
  
# Initializing the input array 
x = np.array([6 , 3])
  
# Calculating the L2 norm
a = linalg.norm(x)
  
# Calculating the L1 norm
b = linalg.norm(x , 1)
  
# Displaying the norm values
print(a)
print(b)


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.

Similar Reads

Solving the linear equations

The linalg.solve function is used to solve the given linear equations. It is used to evaluate the equations automatically and find the values of the unknown variables....

Calculating the Inverse of a Matrix

...

Calculating the Pseudo Inverse of a Matrix

The scipy.linalg.inv is used to find the inverse of a matrix....

Finding the Determinant of a Matrix

...

Singular Value Decomposition

To evaluate the (Moore-Penrose) pseudo-inverse of a matrix, scipy.linalg.pinv is used....

Eigenvalues and EigenVectors

...

Calculating the norm

The determinant of a square matrix is a value derived arithmetically from the coefficients of the matrix. In the linalg module, we use the linalg.det() function to find the determinant of a matrix....

More Matrix Functions

...