Returns a symmetric matrix from a sparse square matrix :math:`A`. Only the
    lower triangular entries of :math:`A` are accessed.

def symmetrize(A):
    """
    Returns a symmetric matrix from a sparse square matrix :math:`A`. Only the
    lower triangular entries of :math:`A` are accessed.
    """
    assert type(A) is spmatrix, "argument must be a sparse matrix"
    assert A.size[0] == A.size[1], "argument must me a square matrix"
    idx = [i for i,ij in enumerate(zip(A.I,A.J)) if ij[0] > ij[1]]
    return tril(A) + spmatrix(A.V[idx], A.J[idx], A.I[idx], A.size)