Some sparse matrix utilities missing in scipy.
compose_sparse(blocks, row_sizes=None, col_sizes=None)¶
Compose sparse matrices into a global sparse matrix.
- blockssequence of sequences
The sequence of sequences of equal lengths - the individual sparse matrix blocks. The integer 0 can be used to mark an all-zero block, if its size can be determined from the other blocks.
- row_sizessequence, optional
The required row sizes of the blocks. It can be either a sequence of non-negative integers, or a sequence of slices with non-negative limits. In any case the sizes have to be compatible with the true block sizes. This allows to extend the matrix shape as needed and to specify sizes of all-zero blocks.
- col_sizessequence, optional
The required column sizes of the blocks. See row_sizes.
The sparse matrix (COO format) composed from the given blocks.
Stokes-like problem matrix.
>>> import scipy.sparse as sp >>> A = sp.csr_matrix([[1, 0], [0, 1]]) >>> B = sp.coo_matrix([[1, 1]]) >>> K = compose_sparse([[A, B.T], [B, 0]]) >>> print K.todense() [[1 0 1] [0 1 1] [1 1 0]]
Infinity norm of a sparse matrix (maximum absolute row sum).
- mtxspmatrix or array
The sparse matrix.
Infinity norm of the matrix.
dense matrix norms
This serves as an upper bound on spectral radius.
CSR and CSC avoid copying indices and indptr arrays.
inspired by PyAMG
insert_sparse_to_csr(mtx1, mtx2, irs, ics)¶
Insert a sparse matrix mtx2 into a CSR sparse matrix mtx1 at rows irs and columns ics. The submatrix mtx1[irs,ics] must already be preallocated and have the same structure as mtx2.
save_sparse_txt(filename, mtx, fmt='%d %d %f\n')¶
Save a CSR/CSC sparse matrix into a text file