sparse — COO / CSR Conversion¶
Source: crates/fastdpplot-core/src/sparse.rs
to_coo¶
Convert a BinGrid to COO format (rows, cols, data).
Only bins where count > 0 are included. The result is suitable for:
scipy.sparse.coo_matrix((data, (rows, cols)), shape=(height, width))- PyArrow / pandas COO → dense conversion.
Example (Rust)¶
Example (Python, via PyO3)¶
to_csr¶
Convert a BinGrid to CSR format (indptr, indices, data).
Only bins where count > 0 are included. Pass directly to scipy:
CSR vs COO
CSR is more efficient for row slicing; COO is more convenient for
column-based operations. Both are available in Rust; only to_coo is
currently exposed via PyO3. Use to_scipy_sparse() in Python for
an automatic CSR result.
Python helper¶
The fastdpplot.sparse_convert.to_scipy_sparse Python function calls
to_coo internally and wraps the result in a scipy.sparse.csr_matrix.
See the Python API — sparse_convert page.