144. Python Program to check given matrix is Symmetric or Not.
How does this program work?
- In this program we are going to learn about how to check given matrix is Symmetric or not using Python.
- Symmetric matrix means Original matrix and Transpose of the given matrix should be in equal.
- Find the Transpose of the given matrix.
- After that to check these two matrices are equal or not, If these are equal it is Symmetric else it is not Symmetric matrix.
Here is the code
def Symmetric(a, n):
for i in range(n):
for j in range(n):
if (a[i][j] != a[j][i]):
return False
return True
a = [ [ 1, 3, 5 ], [ 3, 2, 4 ], [ 5, 4, 9 ] ]
print("Given matrix: ")
print(a)
if (Symmetric(a, 3)):
print ("Given matrix is symmetric")
else:
print ("Given matrix is not a symmetrics")