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 Compute the determinant of a given square array using NumPy in Python In Python, the determinant of a square array can be easily calculated using the NumPy package. This package is used to perform mathematical calculations on single and multi-dimensional arrays. numpy.linalg is an important module of NumPy package which is used for linear algebra. We can use det() fun 2 min read How to inverse a matrix using NumPy In this article, we will see NumPy Inverse Matrix in Python before that we will try to understand the concept of it. 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 variable 3 min read Compute the factor of a given array by Singular Value Decomposition using NumPy Singular Value Decomposition means when arr is a 2D array, it is factorized as u and vh, where u and vh are 2D unitary arrays and s is a 1D array of aâs singular values. numpy.linalg.svd() function is used to compute the factor of an array by Singular Value Decomposition. Syntax : numpy.linalg.svd(a 2 min read Counting the number of non-NaN elements in a NumPy Array In this article, we are going to see how to count the number of non-NaN elements in a NumPy array in Python. NAN: It is used when you don't care what the value is at that position. Maybe sometimes is used in place of missing data, or corrupted data. Method 1: Using Condition In this example, we wil 3 min read Like