- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python – scipy.linalg.norm
The norm() function of the scipy.linalg package is used to return one of eight different matrix norms or one of an infinite number of vector norms.
Syntax
scipy.linalg.norm(x)
Where x is an input array or a square matrix.
Example 1
Let us consider the following example −
# Importing the required libraries from scipy from scipy import linalg import numpy as np # Define the input array x = np.array([7 , 4]) print("Input array:
", x) # Calculate the L2 norm r = linalg.norm(x) # Calculate the L1 norm s = linalg.norm(x, 3) # Display the norm values print("Norm Value of r :", r) print("Norm Value of s :", s)
Output
The above program will generate the following output −
Input array: [7 4] Norm Value of r : 8.06225774829855 Norm Value of s : 7.410795055420619
Example 2
Let us take another example −
# Importing the required libraries from scipy from scipy import linalg import numpy as np # Define the input array x = np.array([[ 6, 7, 8], [9, -1, -2]]) print("Input Array :
", x) # Calculate the L2 norm p = linalg.norm(x) # Calculate the L1 norm q = linalg.norm(x, axis=1) # Display the norm values print("Norm Values of P :", p) print("Norm Values of Q :", q)
Output
It will produce the following output −
Input Array : [[ 6 7 8] [ 9 -1 -2]] Norm Values of P : 15.329709716755891 Norm Values of Q : [12.20655562 9.2736185 ]
- Related Articles
- How do I install Python SciPy?
- What are various sub-packages in Python SciPy library?
- How to solve triangular matrix equations using Python SciPy?
- Return the infinity Norm of the matrix in Linear Algebra in Python
- Return the Frobenius Norm of the matrix in Linear Algebra in Python
- Return the Nuclear Norm of the matrix in Linear Algebra in Python
- How can discrete Fourier transform be performed in SciPy Python?
- How to solve a circulant matrix equation using Python SciPy?
- Return the negative infinity Norm of the matrix in Linear Algebra in Python
- Return the Norm of the matrix or vector in Linear Algebra in Python
- Return the Norm of the matrix over axis in Linear Algebra in Python
- norm() function in C++ with Examples
- Explain how Nelder-Mead algorithm can be implemented using SciPy Python?
- What is the use of scipy.interpolate.interp1d class of SciPy python library?
- How to solve Hermitian positive-banded matrix equation using Python SciPy?
- Return the Norm of the vector over given axis in Linear Algebra in Python

Advertisements