sputils (Sparse Matrix Utilities)
Utility functions for scipy sparse matrices
- rbf.sputils.add_rows(A, B, idx)
This adds the sparse matrix B to rows idx of the sparse matrix A
- Parameters:
A ((n1, m) sparse matrix) – CSC, CSR, BSR, or COO matrix for best efficiency
B ((n2, m) sparse matrix) – CSC, CSR, BSR, or COO matrix for best efficiency
idx ((n2,) int array) – rows of A that B will be added to
- Returns:
(n1, m) COO sparse matrix
- rbf.sputils.divide_rows(A, x, inplace=False)
Divide the rows of the sparse matrix A by x. If inplace is True and A is CSC, CSR, BSR, or COO, then the operation is done in place.
- Parameters:
A ((n, m) sparse matrix) – CSC, CSR, BSR, or COO matrix for best efficiency
x ((n,) float array) –
inplace (bool) – Whether to modify the data in A inplace. This is only possible if A is CSC, CSR, BSR, or COO.
- Returns:
(n, m) COO sparse matrix
- rbf.sputils.expand_cols(A, cols, cout, copy=False)
expand A along the columns.
- Parameters:
A ((rin, cin) sparse matrix) – CSC, CSR, BSR, or COO matrix for best efficiency
cols ((rin,) int array) – The column in the output matrix that each column in A will be assigned to
cout (int) – The number of columns in the output matrix
copy (bool,) – Whether the data in the output matrix should be a copy of the data in A
- Returns:
(rin, cout) COO sparse matrix
- rbf.sputils.expand_rows(A, rows, rout, copy=False)
expand A along the rows.
- Parameters:
A ((rin, cin) sparse matrix) – CSC, CSR, BSR, or COO matrix for best efficiency
rows ((rin,) int array) – The row in the output matrix that each row in A will be assigned to
rout (int) – The number of rows in the output matrix
copy (bool,) – Whether the data in the output matrix should be a copy of the data in A
- Returns:
(rout, cin) COO sparse matrix
- rbf.sputils.row_norms(A, order=2)
Computes the norm of each row in A. This is more memory efficient than scipy.sparse.linalg.norm because it does not make a full copy of the matrix
- Parameters:
A ((n, m) float sparse matrix) – CSC, CSR, BSR, or COO matrix for best efficiency
order (int) –
- Returns:
(n,) float array