{"record":{"id":"ded482b6c492a1ec","repo":"TheAlgorithms/Python","slug":"addition-requires-matrices-of-the-same-order","errorCode":null,"errorMessage":"Addition requires matrices of the same order","messagePattern":"Addition requires matrices of the same order","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"matrix/matrix_class.py","lineNumber":300,"sourceCode":"                [*self.rows[i][0:position], column[i], *self.rows[i][position:]]\n                for i in range(self.num_rows)\n            ]\n\n    # MATRIX OPERATIONS\n    def __eq__(self, other: object) -> bool:\n        if not isinstance(other, Matrix):\n            return NotImplemented\n        return self.rows == other.rows\n\n    def __ne__(self, other: object) -> bool:\n        return not self == other\n\n    def __neg__(self) -> Matrix:\n        return self * -1\n\n    def __add__(self, other: Matrix) -> Matrix:\n        if self.order != other.order:\n            raise ValueError(\"Addition requires matrices of the same order\")\n        return Matrix(\n            [\n                [self.rows[i][j] + other.rows[i][j] for j in range(self.num_columns)]\n                for i in range(self.num_rows)\n            ]\n        )\n\n    def __sub__(self, other: Matrix) -> Matrix:\n        if self.order != other.order:\n            raise ValueError(\"Subtraction requires matrices of the same order\")\n        return Matrix(\n            [\n                [self.rows[i][j] - other.rows[i][j] for j in range(self.num_columns)]\n                for i in range(self.num_rows)\n            ]\n        )\n\n    def __mul__(self, other: Matrix | float) -> Matrix:","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/matrix/matrix_class.py#L282-L318","documentation":"Error \"Addition requires matrices of the same order\" thrown in TheAlgorithms/Python.","triggerScenarios":"Thrown at matrix/matrix_class.py:300 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add only matrices with identical dimensions."],"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-15T22:17:37.221Z"}