import numpy as np from scipy.sparse import coo_array row = np.array([0, 0, 1, 2, 2]) col = np.array([0, 2, 2, 0, 0]) data = np.array([10, 3, 8, 4, 6], dtype=float) coo = coo_array((data, (row, col)), shape=(3, 4)) csr = coo.tocsr() weights = np.array([1.0, 2.0, 0.5, 0.0]) print("coo format:", coo.format) print("coo shape:", coo.shape) print("coo stored values:", coo.nnz) print("csr format:", csr.format) print("csr stored values:", csr.nnz) print("dense rows:") for dense_row in csr.toarray(): print(dense_row) print("row totals:", np.asarray(csr.sum(axis=1)).ravel()) print("matrix-vector product:", csr @ weights)