# 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!!
```

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates