bundles / scipy latest / scipy / sparse / linalg / _dsolve / linsolve / spsolve
function
scipy.sparse.linalg._dsolve.linsolve:spsolve
Signature
def spsolve ( A , b , permc_spec = None , use_umfpack = True ) Summary
Solve the sparse linear system Ax=b, where b may be a vector or a matrix.
Parameters
A: ndarray or sparse array or matrixThe square matrix A will be converted into CSC or CSR form
b: ndarray or sparse array or matrixThe matrix or vector representing the right hand side of the equation. If a vector, b.shape must be (n,) or (n, 1).
permc_spec: str, optionalHow to permute the columns of the matrix for sparsity preservation. (default: 'COLAMD')
use_umfpack: bool, optionalif True (default) then use UMFPACK for the solution [3], [4], [5], [6] . This is only referenced if b is a vector and
scikits.umfpackis installed.
Returns
x: ndarray or sparse array or matrixthe solution of the sparse linear equation. If b is a vector, then x is a vector of size A.shape[1] If b is a matrix, then x is a matrix of size (A.shape[1], b.shape[1])
Notes
For solving the matrix expression AX = B, this solver assumes the resulting matrix X is sparse, as is often the case for very sparse inputs. If the resulting X is dense, the construction of this sparse result will be relatively expensive. In that case, consider converting A to a dense matrix and using scipy.linalg.solve or its variants.
Examples
import numpy as np from scipy.sparse import csc_array from scipy.sparse.linalg import spsolve A = csc_array([[3, 2, 0], [1, -1, 0], [0, 5, 1]], dtype=float) B = csc_array([[2, 0], [-1, 0], [2, 0]], dtype=float) x = spsolve(A, B) np.allclose(A.dot(x).toarray(), B.toarray())✓
Aliases
-
scipy.sparse.linalg.spsolve