NumPy: Calculate the Frobenius norm and the condition number of a given array
NumPy: Linear Algebra Exercise-19 with Solution
Write a NumPy program to calculate the Frobenius norm and the condition number of a given array.
Sample Solution:
Python Code :
# Importing the NumPy library
import numpy as np
# Creating a 3x3 NumPy array 'a' with values from 1 to 9 and reshaping it
a = np.arange(1, 10).reshape((3, 3))
# Display the original array 'a'
print("Original array:")
print(a)
# Compute and display the Frobenius norm and condition number using 'fro' for a given array 'a'
print("Frobenius norm and the condition number:")
print(np.linalg.norm(a, 'fro')) # Compute Frobenius norm using np.linalg.norm()
print(np.linalg.cond(a, 'fro')) # Compute condition number using np.linalg.cond()
Sample Output:
Original array: [[1 2 3] [4 5 6] [7 8 9]] Frobenius norm and the condition number: 16.8819430161 4.56177073661e+17
Python-Numpy Code Editor:
Previous: Write a NumPy program to compute the factor of a given array by Singular Value Decomposition.
Next: NumPy Random Exercises Home
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://198.211.115.131/python-exercises/numpy/linear-algebra/numpy-linear-algebra-exercise-19.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics