Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Numpy exercise
  • pandas
  • Matplotlib
  • Data visulisation
  • EDA
  • Machin Learning
  • Deep Learning
  • NLP
  • Data science
  • ML Tutorial
  • Computer Vision
  • ML project
Open In App
Next Article:
Compute the condition number of a given matrix using NumPy
Next article icon

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  

Next Article
Compute the condition number of a given matrix using NumPy

G

geekmonkey
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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences