bundles / scipy 1.17.1 / scipy / sparse / _matrix_io / load_npz
function
scipy.sparse._matrix_io:load_npz
source: /scipy/sparse/_matrix_io.py :84
Signature
def load_npz ( file ) Summary
Load a sparse array/matrix from 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 loaded.
Returns
result: csc_array, csr_array, bsr_array, dia_array or coo_arrayA sparse array/matrix containing the loaded data.
Raises
: OSErrorIf the input file does not exist or cannot be read.
Examples
Store sparse array/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()✗
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()✗
sparse_matrix = sp.sparse.csc_matrix([[0, 0, 3], [4, 0, 0]]) sp.sparse.save_npz('/tmp/sparse_matrix.npz', sparse_matrix) tmp = sp.sparse.load_npz('/tmp/sparse_matrix.npz') sparse_array = sp.sparse.csr_array(tmp)✓
See also
- numpy.load
Load several arrays from a
.npzarchive.- scipy.sparse.save_npz
Save a sparse array/matrix to a file using
.npzformat.
Aliases
-
scipy.sparse.load_npz