Module npyz::sparse [−][src]
Expand description
Tools for reading and writing Scipy sparse matrices in NPZ format.
use std::io; use npyz::sparse; fn main() -> io::Result<()> { let mut npz = npyz::npz::NpzArchive::open("test-data/sparse/csr.npz")?; let mat = sparse::Csr::<i64>::from_npz(&mut npz)?; // sparse matrices have public fields named after the attributes found in scipy. // read or manipulate them however you like! let sparse::Csr { data, indices, indptr, shape } = &mat; println!("Shape: {:?}", shape); println!("Indices: {:?}", indices); println!("Indptr: {:?}", indptr); println!("Data: {:?}", data); // write to any io::Write let writer = io::BufWriter::new(std::fs::File::create("examples/output/sparse-doctest.npz")?); mat.write_npz(&mut npyz::npz::NpzWriter::new(writer))?; Ok(()) }
No methods are provided on these types beyond reading and writing. If you want to do sparse matrix math, then you should use the data you have read to construct a matrix type from a dedicated sparse matrix library.
For instance, an example of how to use this module to save and load CSR matrices from the
sprs
crate can be found
in the examples directory.
This module requires the "npz"
feature.
Structs
Raw representation of a scipy.sparse.bsr_matrix
.
Raw representation of a scipy.sparse.coo_matrix
.
Raw representation of a scipy.sparse.csc_matrix
.
Raw representation of a scipy.sparse.csr_matrix
.
Raw representation of a scipy.sparse.dia_matrix
.
Enums
Raw representation of a scipy sparse matrix whose exact format is known at runtime.