spsolve#
- scipy.sparse.linalg.spsolve(A, b, permc_spec=None, use_umfpack=True)[source]#
求解稀疏线性方程组 Ax=b,其中 b 可以是向量或矩阵。
- 参数:
- 返回值:
- xndarray 或稀疏矩阵
稀疏线性方程的解。如果 b 为向量,则 x 为大小为 A.shape[1] 的向量。如果 b 为矩阵,则 x 为大小为 (A.shape[1], b.shape[1]) 的矩阵。
注释
对于求解矩阵表达式 AX = B,此求解器假设结果矩阵 X 是稀疏的,就像对于非常稀疏的输入通常情况一样。如果结果 X 是稠密的,则构建此稀疏结果将比较昂贵。在这种情况下,考虑将 A 转换为稠密矩阵并使用 scipy.linalg.solve 或其变体。
参考文献
[1]T. A. Davis, J. R. Gilbert, S. Larimore, E. Ng, Algorithm 836: COLAMD, an approximate column minimum degree ordering algorithm, ACM Trans. on Mathematical Software, 30(3), 2004, pp. 377–380. DOI:10.1145/1024074.1024080
[2]T. A. Davis, J. R. Gilbert, S. Larimore, E. Ng, A column approximate minimum degree ordering algorithm, ACM Trans. on Mathematical Software, 30(3), 2004, pp. 353–376. DOI:10.1145/1024074.1024079
[3]T. A. Davis, Algorithm 832: UMFPACK - an unsymmetric-pattern multifrontal method with a column pre-ordering strategy, ACM Trans. on Mathematical Software, 30(2), 2004, pp. 196–199. https://dl.acm.org/doi/abs/10.1145/992200.992206
[4]T. A. Davis, A column pre-ordering strategy for the unsymmetric-pattern multifrontal method, ACM Trans. on Mathematical Software, 30(2), 2004, pp. 165–195. https://dl.acm.org/doi/abs/10.1145/992200.992205
[5]T. A. Davis and I. S. Duff, A combined unifrontal/multifrontal method for unsymmetric sparse matrices, ACM Trans. on Mathematical Software, 25(1), 1999, pp. 1–19. https://doi.org/10.1145/305658.287640
[6]T. A. Davis and I. S. Duff, An unsymmetric-pattern multifrontal method for sparse LU factorization, SIAM J. Matrix Analysis and Computations, 18(1), 1997, pp. 140–158. https://doi.org/10.1137/S0895479894246905T.
示例
>>> import numpy as np >>> from scipy.sparse import csc_matrix >>> from scipy.sparse.linalg import spsolve >>> A = csc_matrix([[3, 2, 0], [1, -1, 0], [0, 5, 1]], dtype=float) >>> B = csc_matrix([[2, 0], [-1, 0], [2, 0]], dtype=float) >>> x = spsolve(A, B) >>> np.allclose(A.dot(x).toarray(), B.toarray()) True