参考:
https://stackoverflow.com/questions/48798893/error-in-checking-symmetric-sparse-matrix
import scipy.sparse as sp
import numpy as np
np.random.seed(1)
a = sp.random(5, 5, density=0.5)
a
结果如下
sym_err = a - a.T
sym_check_res = np.all(np.abs(sym_err.data) < 1e-10) # tune this value
print(sym_check_res)
adj_dense =np.array([[0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
print(adj_dense)
adj = sp.csr_matrix(adj_dense)
adj
sym_err = adj - adj.T
sym_check_res=np.all(np.abs(sym_err.data) < 1e-10)
print(sym_check_res)