To write a program to find the 2-norm of the matrix and display the result in two decimal places.
- Hardware – PCs
- Anaconda – Python 3.7 Installation / Moodle-Code Runner
1. Get the input matrix using np.array()
2. The 2-Norm of a matrix is given by
3. Find the 2-norm of the matrix using np.linalg.norm()
4. Print the norm of the matrix in two decimal places.
import numpy as np
n = eval(input())
val = np.linalg.norm(n,2)
print("{:.2f}".format(val))
Thus the program for 2-norm of a matrix is written and verified.