Python 中是否有高斯消元的标准解决方案?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15638650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 20:36:04  来源:igfitidea点击:

Is there a standard solution for Gauss elimination in Python?

pythonmatrixnumpy

提问by flonk

Is there somewhere in the cosmos of scipy/numpy/...a standard method for Gauss-elimination of a matrix?

scipy/numpy/...矩阵的高斯消元标准方法在宇宙中的某个地方是否存在?

One finds many snippets via google, but I would prefer to use "trusted" modules if possible.

人们通过谷歌找到了许多片段,但如果可能的话,我更愿意使用“受信任的”模块。

采纳答案by flonk

I finally found, that it can be done using LU decomposition. Here the Umatrix represents the reduced form of the linear system.

我终于发现,它可以使用LU 分解来完成。这里U矩阵表示线性系统的简化形式。

from numpy import array
from scipy.linalg import lu

a = array([[2.,4.,4.,4.],[1.,2.,3.,3.],[1.,2.,2.,2.],[1.,4.,3.,4.]])

pl, u = lu(a, permute_l=True)

Then ureads

然后u

array([[ 2.,  4.,  4.,  4.],
       [ 0.,  2.,  1.,  2.],
       [ 0.,  0.,  1.,  1.],
       [ 0.,  0.,  0.,  0.]])

Depending on the solvability of the system this matrix has an upper triangular or trapezoidal structure. In the above case a line of zeros arises, as the matrix has only rank 3.

根据系统的可解性,该矩阵具有上三角或梯形结构。在上述情况下,出现一行零,因为矩阵只有 rank 3