I am currently trying to implement some linear algebra functions without numpy.
Given some n by n matrix (stored as lists of lists):
[
[a, b, c, d],
[e, f, g, h],
[i, j, k, l],
[m, n, o, p]
]
How do I confirm if such matrix is symmetric (the above matrix is equal to the following matrix) without numpy?:
[
[a, e, i, m],
[b, f, j, n],
[c, g, k, o],
[d, h, l, p]
]
For example,
[
[1, 2, 3],
[2, 3, 4],
[3, 4, 5]
]
and
[
[1, 7, 3],
[7, 4, 5],
[3, 5, 0]
]
are symmetric.
I know the function below works, but this function double counts:
def check_symmetric(array):
dimensions = len(array)
for i in range(dimensions):
for j in range(dimensions):
if i != j:
if not(array[i][j] == array[j][i]):
return False
return True
Is there a more efficient implementation?