Checking if a matrix is symmetric in Numpy
You can simply compare it to its transpose using allclose
def check_symmetric(a, rtol=1e-05, atol=1e-08):
return numpy.allclose(a, a.T, rtol=rtol, atol=atol)
The following function also solves the problem:
def check_symmetric(a, tol=1e-8):
return np.all(np.abs(a-a.T) < tol)