python runtime_error ai_generated true

numpy.linalg.LinAlgError: Singular matrix

ID: python/numpy-linalg-singular

Also available as: JSON · Markdown · 中文
80%Fix Rate
90%Confidence
0Evidence
2024-03-27First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active — — —

Root Cause

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

generic

中文

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

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 80% fail

    Perturbation may still be singular; unstable results

  2. 70% fail

    Ill-conditioned; large numerical error