(
    data: sp.csc_matrix | sp.csr_matrix,
    filepath: types.PathLike,
    *,
    compressed: bool = True,
    make_dirs: bool = False,
)
Write sparse matrix ``data`` to disk at ``filepath``, optionally compressed,
    into a single ``.npz`` file.

    Args:
        data
        filepath: Path to file on disk to which data will be written. If ``filepath``
            does not end in ``.npz``, that extension is automatically appended to the name.
        compressed: If True, save arrays into a single file in compressed numpy binary format.
        make_dirs: If True, automatically create (sub)directories
            if not already present in order to write ``filepath``.

    See Also:
        https://docs.scipy.org/doc/numpy-1.13.0/reference/routines.io.html#numpy-binary-files-npy-npz
Write sparse matrix ``data`` to disk at ``filepath``, optionally compressed,
    into a single ``.npz`` file.
Write sparse matrix data to disk at filepath optionally compressed into a single . npz file .
def write_sparse_matrix(
    data: sp.csc_matrix | sp.csr_matrix,
    filepath: types.PathLike,
    *,
    compressed: bool = True,
    make_dirs: bool = False,
) -> None:
    """
    Write sparse matrix ``data`` to disk at ``filepath``, optionally compressed,
    into a single ``.npz`` file.

    Args:
        data
        filepath: Path to file on disk to which data will be written. If ``filepath``
            does not end in ``.npz``, that extension is automatically appended to the name.
        compressed: If True, save arrays into a single file in compressed numpy binary format.
        make_dirs: If True, automatically create (sub)directories
            if not already present in order to write ``filepath``.

    See Also:
        https://docs.scipy.org/doc/numpy-1.13.0/reference/routines.io.html#numpy-binary-files-npy-npz
    """
    if not isinstance(data, (sp.csc_matrix, sp.csr_matrix)):
        raise TypeError(
            errors.type_invalid_msg(
                "data", type(data), Union[sp.csc_matrix, sp.csr_matrix]
            )
        )
    filepath = utils.to_path(filepath).resolve()
    if make_dirs is True:
        io_utils._make_dirs(filepath, "w")
    if compressed is True:
        np.savez_compressed(
            str(filepath),
            data=data.data,
            indices=data.indices,
            indptr=data.indptr,
            shape=data.shape,
        )
    else:
        np.savez(
            str(filepath),
            data=data.data,
            indices=data.indices,
            indptr=data.indptr,
            shape=data.shape,
        )
def write_sparse_matrix ( data : sp . csc_matrix | sp . csr_matrix , filepath : types . PathLike , * , compressed : bool = True , make_dirs : bool = False , ) -> None : if not isinstance ( data , ( sp . csc_matrix , sp . csr_matrix ) ) : raise TypeError ( errors . type_invalid_msg ( "data" , type ( data ) , Union [ sp . csc_matrix , sp . csr_matrix ] ) ) filepath = utils . to_path ( filepath ) . resolve ( ) if make_dirs is True : io_utils . _make_dirs ( filepath , "w" ) if compressed is True : np . savez_compressed ( str ( filepath ) , data = data . data , indices = data . indices , indptr = data . indptr , shape = data . shape , ) else : np . savez ( str ( filepath ) , data = data . data , indices = data . indices , indptr = data . indptr , shape = data . shape , )