lacuna.sparse.coo#
Classes
|
Coordinate (COO) sparse matrix. |
- class lacuna.sparse.coo.COO(row, col, data, shape, dtype=<class 'numpy.float64'>, check=True)[source]#
Bases:
SparseArrayCoordinate (COO) sparse matrix.
- Parameters:
row (array_like of int64) – Row indices for nonzero entries, length
nnz.col (array_like of int64) – Column indices for nonzero entries, length
nnz.data (array_like of float64) – Nonzero values, length
nnz.dtype (numpy.dtype, optional) – Value dtype, defaults to
np.float64.check (bool, optional) – If True, validate invariants in the native layer (may be slower).
- row, col, data
Storage arrays for indices and values.
- Type:
- dtype#
Value dtype.
- Type:
Notes
Backed by Rust kernels through
lacuna._core.Coo64; operations release the GIL.Examples
Construct a small COO and run basic ops:
>>> import numpy as np >>> from lacuna.sparse import COO >>> row = np.array([0, 1, 1]) >>> col = np.array([0, 0, 2]) >>> val = np.array([1.0, 2.0, 3.0]) >>> a = COO(row, col, val, shape=(2, 3)) >>> a.nnz 3 >>> (a @ np.array([1.0, 0.0, 1.0])).tolist() # SpMV [1.0, 3.0] >>> a.sum() 6.0
- property T#
- classmethod from_arrays(row, col, data, shape, check=True)[source]#
Construct from index/value arrays.
- property nnz#
Number of stored values (including duplicates).