(
    filepath: types.PathLike, *, kind: str = "csc",
)
Read the data, indices, indptr, and shape arrays from a ``.npz`` file on disk
    at ``filepath``, and return an instantiated sparse matrix.

    Args:
        filepath: Path to file on disk from which data will be read.
        kind ({'csc', 'csr'}): Kind of sparse matrix to instantiate.

    Returns:
        An instantiated sparse matrix, whose type depends on the value of ``kind``.

    See Also:
        https://docs.scipy.org/doc/numpy-1.13.0/reference/routines.io.html#numpy-binary-files-npy-npz
Read the data, indices, indptr, and shape arrays from a ``.npz`` file on disk
    at ``filepath``, and return an instantiated sparse matrix.
Read the data indices indptr and shape arrays from a . npz file on disk at filepath and return an instantiated sparse matrix .
def read_sparse_matrix(
    filepath: types.PathLike, *, kind: str = "csc",
) -> sp.csc_matrix | sp.csr_matrix:
    """
    Read the data, indices, indptr, and shape arrays from a ``.npz`` file on disk
    at ``filepath``, and return an instantiated sparse matrix.

    Args:
        filepath: Path to file on disk from which data will be read.
        kind ({'csc', 'csr'}): Kind of sparse matrix to instantiate.

    Returns:
        An instantiated sparse matrix, whose type depends on the value of ``kind``.

    See Also:
        https://docs.scipy.org/doc/numpy-1.13.0/reference/routines.io.html#numpy-binary-files-npy-npz
    """
    npz_file = np.load(filepath)
    if kind == "csc":
        return sp.csc_matrix(
            (npz_file["data"], npz_file["indices"], npz_file["indptr"]),
            shape=npz_file["shape"],
        )
    elif kind == "csr":
        return sp.csr_matrix(
            (npz_file["data"], npz_file["indices"], npz_file["indptr"]),
            shape=npz_file["shape"],
        )
    else:
        raise ValueError(errors.value_invalid_msg("kind", kind, {"csc", "csr"}))
def read_sparse_matrix ( filepath : types . PathLike , * , kind : str = "csc" , ) -> sp . csc_matrix | sp . csr_matrix : npz_file = np . load ( filepath ) if kind == "csc" : return sp . csc_matrix ( ( npz_file [ "data" ] , npz_file [ "indices" ] , npz_file [ "indptr" ] ) , shape = npz_file [ "shape" ] , ) elif kind == "csr" : return sp . csr_matrix ( ( npz_file [ "data" ] , npz_file [ "indices" ] , npz_file [ "indptr" ] ) , shape = npz_file [ "shape" ] , ) else : raise ValueError ( errors . value_invalid_msg ( "kind" , kind , { "csc" , "csr" } ) )