import numpy as np
def is_symmetric(A):
return (np.array(A) == np.array(A).transpose()).all()
def is_skew(A):
return (np.array(A) == -np.array(A).transpose()).all()
def test_matrix(A):
if is_symmetric(A):
return 1
if is_skew(A):
return -1
else:
return 0
if __name__ == '__main__':
a, b, c, d, e, f, g, h, i = 0,1,2,3,4,5,6,7,8
symmetric_A = [[a, b, c],
[b, c, a],
[c, a, b]]
skew_A = [[0, -b, -c],
[b, 0, -a],
[c, a, 0]]
arbitrary_A = [[a, b, c],
[d, e, f],
[g, h, i]]
print("Testing with symmetric matrix ", test_matrix(symmetric_A))
print("Testing with arbitrary matrix ", test_matrix(arbitrary_A))
print("Testing with skew matrix ", test_matrix(skew_A))
Output:
Testing with symmetric matrix 1
Testing with arbitrary matrix 0
Testing with skew matrix -1