save_npz
Save a sparse matrix to disk in numpy's .npz
format.
Note: This is not binary compatible with scipy's save_npz()
.
This binary format is not currently stable. Will save a file
that can only be opend with this package's load_npz()
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
string or file
|
Either the file name (string) or an open file (file-like object)
where the data will be saved. If file is a string or a Path, the
|
required |
matrix
|
SparseArray
|
The matrix to save to disk |
required |
compressed
|
bool_
|
Whether to save in compressed or uncompressed mode |
True
|
Examples:
Store sparse matrix to disk, and load it again:
>>> import os
>>> import sparse
>>> import numpy as np
>>> dense_mat = np.array([[[0.0, 0.0], [0.0, 0.70677779]], [[0.0, 0.0], [0.0, 0.86522495]]])
>>> mat = sparse.COO(dense_mat)
>>> mat
<COO: shape=(2, 2, 2), dtype=float64, nnz=2, fill_value=0.0>
>>> sparse.save_npz("mat.npz", mat)
>>> loaded_mat = sparse.load_npz("mat.npz")
>>> loaded_mat
<COO: shape=(2, 2, 2), dtype=float64, nnz=2, fill_value=0.0>
>>> os.remove("mat.npz")
Source code in sparse/numba_backend/_io.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|