{"record":{"id":"9136fd141b237763","repo":"TheAlgorithms/Python","slug":"only-matrices-with-a-non-zero-determinant-have-an","errorCode":null,"errorMessage":"Only matrices with a non-zero determinant have an inverse","messagePattern":"Only matrices with a non-zero determinant have an inverse","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"matrix/matrix_class.py","lineNumber":226,"sourceCode":"                    if (row + column) % 2 == 0\n                    else self.minors().rows[row][column] * -1\n                    for column in range(self.minors().num_columns)\n                ]\n                for row in range(self.minors().num_rows)\n            ]\n        )\n\n    def adjugate(self) -> Matrix:\n        values = [\n            [self.cofactors().rows[column][row] for column in range(self.num_columns)]\n            for row in range(self.num_rows)\n        ]\n        return Matrix(values)\n\n    def inverse(self) -> Matrix:\n        determinant = self.determinant()\n        if not determinant:\n            raise TypeError(\"Only matrices with a non-zero determinant have an inverse\")\n        return self.adjugate() * (1 / determinant)\n\n    def __repr__(self) -> str:\n        return str(self.rows)\n\n    def __str__(self) -> str:\n        if self.num_rows == 0:\n            return \"[]\"\n        if self.num_rows == 1:\n            return \"[[\" + \". \".join(str(self.rows[0])) + \"]]\"\n        return (\n            \"[\"\n            + \"\\n \".join(\n                [\n                    \"[\" + \". \".join([str(value) for value in row]) + \".]\"\n                    for row in self.rows\n                ]\n            )","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/matrix/matrix_class.py#L208-L244","documentation":"Error \"Only matrices with a non-zero determinant have an inverse\" thrown in TheAlgorithms/Python.","triggerScenarios":"Thrown at matrix/matrix_class.py:226 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Only invertible matrices (non-zero determinant) have an inverse; check the determinant first."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}