def tril(A, k=0, format=None):

    # convert to COOrdinate format where things are easy
    A = coo_matrix(A, copy=False)
    mask = A.row + k >= A.col
    return _masked_coo(A, mask).asformat(format)
Return the lower triangular portion of a matrix in sparse format
dataset/ETHPy150Open scipy/scipy/scipy/sparse/extract.py/tril