Skip to content
geeksforgeeks
  • 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
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Python | sympy.Matrix.col_del() method
Next article icon

Python sympy | Matrix.diagonalize() method

Last Updated : 30 Dec, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
With the help of sympy.Matrix().diagonalize() method, we can diagonalize a matrix. diagonalize() returns a tuple (P, D), where D is diagonal and M = PDP^{-1}.
Syntax: Matrix().diagonalize() Returns: Returns a tuple of matrix where the second element represents the diagonal of the matrix.
Example #1:
# import sympy 
from sympy import * M = Matrix([[3, -2,  4, -2],
                                [5,  3, -3, -2],
                                [5, -2,  2, -2],
                                [5, -2, -3,  3]])
  
print("Matrix : {} ".format(M))
   
# Use sympy.diagonalize() method 
P, D = M.diagonalize()  
      
print("Diagonal of a matrix : {}".format(D))  
                      
                       
Output:
Matrix : Matrix([[3, -2, 4, -2], [5, 3, -3, -2], [5, -2, 2, -2], [5, -2, -3, 3]]) Diagonal of a matrix : Matrix([[-2, 0, 0, 0], [0, 3, 0, 0], [0, 0, 5, 0], [0, 0, 0, 5]])
Example #2:
# import sympy 
from sympy import * M = Matrix([[1, -3, 3], [3, -5, 3], [6, -6, 4]]) 
print("Matrix : {} ".format(M))
   
# Use sympy.diagonalize() method 
P, D = M.diagonalize()  
      
print("Diagonal of a matrix : {}".format(D))
                      
                       
Output:
Matrix : Matrix([[1, -3, 3], [3, -5, 3], [6, -6, 4]]) Diagonal of a matrix : Matrix([[-2, 0, 0], [0, -2, 0], [0, 0, 4]])


Next Article
Python | sympy.Matrix.col_del() method
author
rupesh_rao
Improve
Article Tags :
  • Python
  • Python matrix-program
  • SymPy
Practice Tags :
  • python

Similar Reads

  • Python | sympy.Matrix.eigenvals() method
    With the help of sympy.Matrix.eigenvals() method, we can find the eigen values of the matrix. Syntax : sympy.Matrix().eigenvals() Return : Return the eigen values of a matrix. Example #1 : In the given example we can see that the sympy.Matrix.eigenvals() method is used to find the eigen values of a
    1 min read
  • Python | sympy.Matrix.col() method
    With the help of sympy.Matrix().col() method, we can extract the columns of the matrix. Syntax : sympy.Matrix().col() Return : Return the col of a matrix. Example #1 : In the given example we can see that the sympy.Matrix.col() method is used to extract the columns of a matrix. # Import all the meth
    1 min read
  • Python sympy | Matrix.eigenvects() method
    With the help of sympy.Matrix().eigenvects() method, we can find the Eigenvectors of a matrix. eigenvects() method returns a list of tuples of the form (eigenvalue:algebraic multiplicity, [eigenvectors]). Syntax: Matrix().eigenvects() Returns: Returns a list of tuples of the form (eigenvalue:algebra
    2 min read
  • Python | sympy.Matrix.col_del() method
    With the help of sympy.Matrix.col_del() method, we can delete the columns of the matrix. Syntax : sympy.Matrix().col_del() Return : Return a new matrix. Example #1 : In the given example we can see that the sympy.Matrix.col_del() method is used to delete the column of a matrix and return a new matri
    1 min read
  • Python | sympy.Matrix() method
    With the help of sympy.Matrix() method, we can make, rearrange, extract the different rows and columns in a matrix which is created by sympy.Matrix() method. Syntax : sympy.Matrix() Return : Return a matrix. Example #1 :In this example, we can see that by using sympy.Matrix() method, we can create a
    1 min read
  • Python | sympy.Matrix.row_del() method
    With the help of sympy.Matrix.row_del() method, we can delete the rows of the matrix. Syntax : sympy.Matrix().row_del() Return : Return a new matrix. Example #1 : In the given example we can see that the sympy.Matrix.row_del() method is used to delete the row of a matrix and return a new matrix. # I
    1 min read
  • Python | sympy.diag() method
    With the help of sympy.diag() method, we can create a matrix having dimension nxn and filled with numbers in the diagonal by using sympy.diag() method. Syntax : sympy.diag() Return : Return a new matrix. Example #1 : In this example, we can see that by using sympy.diag() method, we are able to creat
    1 min read
  • Python | sympy.eigenvals() method
    With the help of sympy.eigenvals() method, we can find the eigenvalues of a matrix by using sympy.eigenvals() method. Syntax : sympy.eigenvals() Return : Return eigenvalues of a matrix. Example #1 : In this example, we can see that by using sympy.eigenvals() method, we are able to find the eigenvalu
    1 min read
  • Python | sympy.det() method
    With the help of sympy.det() method, we can find the determinant of a matrix by using sympy.det() method. Syntax : sympy.det() Return : Return determinant of a matrix. Example #1 : In this example, we can see that by using sympy.det() method, we are able to find the determinant of a matrix. # import
    1 min read
  • Python | sympy.Lambda() method
    With the help of sympy.Lambda() method, we can perform any mathematical operation by just defining the formula and then pass the parameters with reference variable by using sympy.Lambda(). Syntax : sympy.Lambda() Return : Return the result of mathematical formula. Example #1 : In this example we can
    1 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