I developed a function (shown below) to check if a sparse matrix is symmetric and would like to know if the community is interested to include in scipy.sparse.Regards,Saullodef is_symmetric(m):"""Check if a sparse matrix is symmetricParameters----------m : array or sparse matrixA square matrix.Returns-------check : boolThe check result."""if m.shape[0] != m.shape[1]:raise ValueError('m must be a square matrix')if not isinstance(m, coo_matrix):m = coo_matrix(m)r, c, v = m.row, m.col, m.datatril_no_diag = r > ctriu_no_diag = c > rif triu_no_diag.sum() != tril_no_diag.sum():return Falserl = r[tril_no_diag]cl = c[tril_no_diag]vl = v[tril_no_diag]ru = r[triu_no_diag]cu = c[triu_no_diag]vu = v[triu_no_diag]sortl = np.lexsort((cl, rl))sortu = np.lexsort((ru, cu))vl = vl[sortl]vu = vu[sortu]check = np.allclose(vl, vu)return check
_______________________________________________
SciPy-Dev mailing list
SciPy-Dev@scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-dev