def write_sparse_matrix(matrix, filename, compressed=False):
    if not isinstance(matrix, (csc_matrix, csr_matrix)):
        raise TypeError('input matrix must be a scipy sparse csr or csc matrix')
    _make_dirs(filename)
    if compressed is False:
        savez(filename,
                 data=matrix.data, indices=matrix.indices,
                 indptr=matrix.indptr, shape=matrix.shape)
    else:
        savez_compressed(filename,
                 data=matrix.data, indices=matrix.indices,
                 indptr=matrix.indptr, shape=matrix.shape)
Write a ``scipy.sparse.csr_matrix`` or ``scipy.sparse.csc_matrix`` to disk
dataset/ETHPy150Open chartbeat-labs/textacy/textacy/fileio/write.py/write_sparse_matrix