To write a program to find the 1-norm, 2-norm and infinity norm of the matrix and display the result in two decimal places.
- Hardware – PCs
- Anaconda – Python 3.7 Installation / Moodle-Code Runner
- Get the input matrix using np.array()
- Find the 2-norm of the matrix using np.linalg.norm()
- Print the norm of the matrix in two decimal places.
#Python program to find the 1-Norm of a matrix and display the results in two decimal places.
#Developed by:Bhuvanesh.S.R
#Reg no:212223240017
import numpy as np
value=eval(input())
arr=np.array(value)
norm=np.linalg.norm(arr,1)
print("{:.2f}".format(norm))
#Python program to find 2-norm of a matrix and display the result in two decimal places.
#Developed by:Bhuvanesh.S.R
#Reg no:212223240017
import numpy as np
value=eval(input())
arr=np.array(value)
norm=np.linalg.norm(arr,2)
print("{:.2f}".format(norm))
#Python program to find the Infinity of a matrix and display the result in two decimal places.
#Developed by:Bhuvanesh.S.R
#Reg no:212223240017
import numpy as np
value=eval(input())
arr=np.array(value)
norm=np.linalg.norm(arr,np.inf)
print("{:.2f}".format(norm))
Thus the program for 1-norm, 2-norm and Infinity norm of a matrix are written and verified.