bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / sparse / _matrix_io / save_npz
function
scipy.sparse._matrix_io:save_npz
source: build-install/usr/lib/python3.14/site-packages/scipy/sparse/_matrix_io.py:11
Signature
def save_npz(file, matrix, compressed = True)Summary
Save a sparse matrix or array to a file using .npz format.
Parameters
file: str or file-like objectEither the file name (string) or an open file (file-like object) where the data will be saved. If file is a string, the
.npzextension will be appended to the file name if it is not already there.matrix: spmatrix or sparrayThe sparse matrix or array to save. Supported formats:
csc,csr,bsr,diaorcoo.compressed: bool, optionalAllow compressing the file. Default: True
Examples
Store sparse matrix to disk, and load it again:import numpy as np import scipy as sp sparse_array = sp.sparse.csc_array([[0, 0, 3], [4, 0, 0]])✓
sparse_array sparse_array.toarray()✗
array([[0, 0, 3],
[4, 0, 0]])
sp.sparse.save_npz('/tmp/sparse_array.npz', sparse_array) sparse_array = sp.sparse.load_npz('/tmp/sparse_array.npz')✓
sparse_array sparse_array.toarray()✗
array([[0, 0, 3],
[4, 0, 0]])
See also
- numpy.savez
Save several arrays into a
.npzarchive.- numpy.savez_compressed
Save several arrays into a compressed
.npzarchive.- scipy.sparse.load_npz
Load a sparse matrix from a file using
.npzformat.
Aliases
scipy.sparse.save_npz