Python 中是否有高斯消元的标准解决方案? [英] Is there a standard solution for Gauss elimination in Python?

查看:28
本文介绍了Python 中是否有高斯消元的标准解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

scipy/numpy/... 的宇宙中是否有一种矩阵高斯消元的标准方法?

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

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

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

推荐答案

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

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

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)

然后u读取

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

根据系统的可解性,该矩阵具有上三角或梯形结构.在上面的例子中,出现了一行零,因为矩阵只有 3.

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.

这篇关于Python 中是否有高斯消元的标准解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆