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.
#Developed By:SORNAKUMAR S
#Register number:212223230210
import numpy as np
mat= eval(input())
a=np.linalg.norm(mat,1)
print("%0.2f"%a)
# 2-Norm of a Matrix
'''
Program to find 2-norm of a matrix.
Developed by: SORNAKUMAR S
RegisterNumber:212223230210
'''
import numpy as np
mat=np.array(eval(input()))
ans=np.linalg.norm(mat,2)
norm_mat="{:.2f}".format(ans)
print(norm_mat)
# Infinity Norm of a Matrix
'''
Program to find the Infinity of a matrix
Developed by:SORNA KUMAR S
Register number:212223230210
'''
import numpy as np
mat=eval(input())
a=np.linalg.norm(mat,np.inf)
print("%0.2f"%a)
Thus the program for 1-norm, 2-norm and Infinity norm of a matrix are written and verified.