spsolve#
- scipy.sparse.linalg.spsolve(A, b, permc_spec=None, use_umfpack=True)[源代码][源代码]#
求解稀疏线性系统 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