Compute the condition number of a given matrix using NumPy Last Updated : 29 Aug, 2020 Comments Improve Suggest changes Like Article 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 Comment More infoAdvertise with us Next Article Compute the condition number of a given matrix using NumPy G geekmonkey Follow Improve Article Tags : Python Numpy Python-numpy Python numpy-Linear Algebra Practice Tags : python Similar Reads Compute the inverse of a matrix using NumPy The inverse of a matrix is just a reciprocal of the matrix as we do in normal arithmetic for a single number which is used to solve the equations to find the value of unknown variables. The inverse of a matrix is that matrix which when multiplied with the original matrix will give as an identity mat 2 min read Calculate the QR decomposition of a given matrix using NumPy In this article, we will discuss QR decomposition of a matrix. QR factorization of a matrix is the decomposition of a matrix say âAâ into âA=QRâ where Q is orthogonal and R is an upper-triangular matrix. We can calculate the QR decomposition of a given matrix with the help of numpy.linalg.qr(). Syn 2 min read How to get the number of dimensions of a matrix using NumPy in Python? In this article, we will discuss how to get the number of dimensions of a matrix using NumPy. It can be found using the ndim parameter of the ndarray() method. Syntax: no_of_dimensions = numpy.ndarray.ndim Approach: Create an n-dimensional matrix using the NumPy package.Use ndim attribute available 3 min read How to Calculate the determinant of a matrix using NumPy? The determinant of a square matrix is a special number that helps determine whether the matrix is invertible and how it transforms space. It is widely used in linear algebra, geometry and solving equations. NumPy provides built-in functions to easily compute the determinant of a matrix, let's explor 2 min read How to Find cofactor of a matrix using Numpy In this article, we are going to see how to find the cofactor of a given matrix using NumPy. There is no direct way to find the cofactor of a given matrix using Numpy. Deriving the formula to find cofactor using the inverse of matrix in Numpy Formula to find the inverse of a matrix: A-1 = ( 1 / det( 2 min read Like