LinAlgError: Last 2 dimensions of the array must be square, matrices cant be solved

LinAlgError: Last 2 dimensions of the array must be square, matrices cant be solved

我正在尝试用 linalg.solve 求解矩阵,但我总是收到错误 LinAlgError:数组的最后 2 个维度必须是正方形。我的错误在哪里? 感谢您的帮助

这是我的代码:

reaktionsgleichung=np.array([[3,1,0,0,0],[5,0,2,0,0],[3,0,0,-2,0],[9,-2,-1,0,-2]])

loesungsvektor=np.array([0,0,0,0,0])

np.linalg.solve(reaktionsgleichung, loesungsvektor)

您的矩阵是 4 x 5 矩阵,不是方阵。

根据numpy.linalg.solve的文档:

Computes the “exact” solution, x, of the well-determined, i.e., full rank, linear matrix equation ax = b.

它只适用于方阵。

考虑 numpy.linalg.lstsq 非方矩阵