Compute the condition number of a given matrix using NumPy Last Updated : 29 Aug, 2020 Comments Improve Suggest changes 1 Likes Like Report In this article, we will use the cond() function of the NumPy package to calculate the condition number of a given matrix. cond() is a function of linear algebra module in NumPy package. Syntax: numpy.linalg.cond(x, p=None) Example 1: Condition Number of 2X2 matrix Python3 # Importing library import numpy as np # Creating a 2X2 matrix matrix = np.array([[4, 2], [3, 1]]) print("Original matrix:") print(matrix) # Output result = np.linalg.cond(matrix) print("Condition number of the matrix:") print(result) Output: Original matrix: [[4 2] [3 1]] Condition number of the matrix: 14.933034373659256 Example 2: Condition Number of 3X3 matrix Python3 # Importing library import numpy as np # Creating a 3X3 matrix matrix = np.array([[4, 2, 0], [3, 1, 2], [1, 6, 4]]) print("Original matrix:") print(matrix) # Output result = np.linalg.cond(matrix) print("Condition number of the matrix:") print(result) Output: Original matrix: [[4 2 0] [3 1 2] [1 6 4]] Condition number of the matrix: 5.347703616656448 Example 3: Condition Number of 4X4 matrix Python3 # Importing library import numpy as np # Creating a 4X4 matrix matrix = np.array([[4, 1, 4, 2], [3, 1, 2, 0], [3, 5, 7 ,1], [0, 6, 8, 4]]) print("Original matrix:") print(matrix) # Output result = np.linalg.cond(matrix) print("Condition number of the matrix:") print(result) Output: Original matrix: [[4 1 4 2] [3 1 2 0] [3 5 7 1] [0 6 8 4]] Condition number of the matrix: 57.34043866386226 Create Quiz Comment G geekmonkey Follow 1 Improve G geekmonkey Follow 1 Improve Article Tags : Numpy Python-numpy Python numpy-Linear Algebra Explore IntroductionNumPy Introduction5 min readPython NumPy6 min readNumPy Array in Python2 min readBasics of NumPy Arrays4 min readNumpy - ndarray3 min readData type Object (dtype) in NumPy Python3 min readCreating NumPy ArrayNumpy - Array Creation5 min readnumpy.arange() in Python2 min readnumpy.zeros() in Python2 min readNumPy - Create array filled with all ones2 min readNumPy - linspace() Function2 min readnumpy.eye() in Python2 min readCreating a one-dimensional NumPy array2 min readHow to create an empty and a full NumPy array2 min readCreate a Numpy array filled with all zeros - Python2 min readHow to generate 2-D Gaussian array using NumPy?2 min readHow to create a vector in Python using NumPy4 min readPython - Numpy fromrecords() method2 min readNumPy Array ManipulationNumPy Copy and View of Array4 min readHow to Copy NumPy array into another array?2 min readAppending values at the end of an NumPy array4 min readHow to swap columns of a given NumPy array?4 min readInsert a new axis within a NumPy array4 min readnumpy.hstack() in Python2 min readnumpy.vstack() in python2 min readJoining NumPy Array3 min readCombining a One and a Two-Dimensional NumPy Array3 min readNumpy np.ma.concatenate() method-Python2 min readNumpy dstack() method-Python2 min readSplitting Arrays in NumPy6 min readHow to compare two NumPy arrays?2 min readFind the union of two NumPy arrays2 min readFind unique rows in a NumPy array3 min readNumpy np.unique() method-Python2 min readnumpy.trim_zeros() in Python2 min read Like