×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Symmetric Matrices | Linear Algebra using Python

Linear Algebra using Python | Symmetric Matrices: Here, we are going to learn about the symmetric matrices and its implementation in Python.
Submitted by Anuj Singh, on May 26, 2020

Prerequisites:

In linear algebra, if the matrix and its transpose are equal, then the matrix is symmetric (MT = M).

In terms of elements of matrices: M(i, j) = M(j, i)

Following is a python code for demonstrating how to check for Symmetric Matrix.

Method:

Syntax:
    M = numpy.array( )
    transpose_M = M.T
    if transpose_M == M:
        Transpose = True 

Return:
    MT

Python code for symmetric matrices

# Linear Algebra Learning Sequence
# Transpose using different Method

import numpy as np

M = np.array([[2,3,4], [3,45,8], [4,8,78]])
print("---Matrix M---\n", M)

# Transposing the Matrix M
print('\n\nTranspose as M.T----\n', M.T)

if M.T.all() == M.all():
    print("--------> Transpose is eqaul to M")
    
M = np.array([[2,3,4], [3,45,8]])
print("\n\n---Matrix B---\n", M)

# Transposing the Matrix M
print('\n\nTranspose as B.T----\n', M.T)

if M.T.all() == M.all() and np.shape(M) == np.shape(M.T):
    print("---------> Transpose is eqaul to B")
    
else:
    print("---------> Not Transpose!!")

Output:

---Matrix M---
 [[ 2  3  4]
 [ 3 45  8]
 [ 4  8 78]]


Transpose as M.T----
 [[ 2  3  4]
 [ 3 45  8]
 [ 4  8 78]]
--------> Transpose is eqaul to M


---Matrix B---
 [[ 2  3  4]
 [ 3 45  8]]


Transpose as B.T----
 [[ 2  3]
 [ 3 45]
 [ 4  8]]
---------> Not Transpose!!
Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.