python runtime_error ai_generated true

numpy.linalg.LinAlgError:奇异矩阵

numpy.linalg.LinAlgError: Singular matrix

ID: python/numpy-linalg-singular

其他格式: JSON · Markdown 中文 · English
80%修复率
90%置信度
0证据数
2024-03-27首次发现

版本兼容性

版本状态引入弃用备注
3.x active — — —

根因分析

矩阵不可逆(行列式为零);线性系统无唯一解。

English

Matrix is not invertible (determinant zero); linear system has no unique solution.

generic

解决方案

  1. 95% 成功率
    x = np.linalg.lstsq(A, b, rcond=None)[0]
  2. 90% 成功率
    x = np.linalg.pinv(A) @ b

无效尝试

常见但无效的做法:

  1. 80% 失败

    Perturbation may still be singular; unstable results

  2. 70% 失败

    Ill-conditioned; large numerical error