scipy.sparse.linalg.SuperLU

class scipy.sparse.linalg.SuperLU

稀疏矩阵的Lu分解。

因式分解表示为::

Pr * A * Pc = L * U

来建造这些 SuperLU 对象,则调用 spluspilu 功能。

注意事项

0.14.0 新版功能.

示例

LU分解可用于求解矩阵方程。请考虑:

>>> import numpy as np
>>> from scipy.sparse import csc_matrix, linalg as sla
>>> A = csc_matrix([[1,2,0,4],[1,0,0,1],[1,0,2,1],[2,2,1,0.]])

对于给定的右侧,可以解决此问题:

>>> lu = sla.splu(A)
>>> b = np.array([1, 2, 3, 4])
>>> x = lu.solve(b)
>>> A.dot(x)
array([ 1.,  2.,  3.,  4.])

这个 lu 对象还包含分解的显式表示形式。排列表示为索引的映射:

>>> lu.perm_r
array([0, 2, 1, 3], dtype=int32)
>>> lu.perm_c
array([2, 0, 1, 3], dtype=int32)

L和U因子是CSC格式的稀疏矩阵:

>>> lu.L.A
array([[ 1. ,  0. ,  0. ,  0. ],
       [ 0. ,  1. ,  0. ,  0. ],
       [ 0. ,  0. ,  1. ,  0. ],
       [ 1. ,  0.5,  0.5,  1. ]])
>>> lu.U.A
array([[ 2.,  0.,  1.,  4.],
       [ 0.,  2.,  1.,  1.],
       [ 0.,  0.,  1.,  1.],
       [ 0.,  0.,  0., -5.]])

排列矩阵可以构造为:

>>> Pr = csc_matrix((np.ones(4), (lu.perm_r, np.arange(4))))
>>> Pc = csc_matrix((np.ones(4), (np.arange(4), lu.perm_c)))

我们可以重组原始矩阵:

>>> (Pr.T * (lu.L * lu.U) * Pc.T).A
array([[ 1.,  2.,  0.,  4.],
       [ 1.,  0.,  0.,  1.],
       [ 1.,  0.,  2.,  1.],
       [ 2.,  2.,  1.,  0.]])
属性
shape

整数元组形式的原始矩阵的形状。

nnz

矩阵中非零元素的数量。

perm_c

排列Pc表示为索引数组。

perm_r

排列PR表示为索引数组。

L

单位对角线为a的下三角因子 scipy.sparse.csc_matrix

U

上三角因子作为 scipy.sparse.csc_matrix

方法:

solve \(RHS[, trans] )

求解具有一个或多个右侧的线性方程组。