{"record":{"id":"7241a05f2adb4f9b","repo":"keras-team/keras","slug":"expected-b-shape-0-to-be-equal-to-a-shape-0-rec","errorCode":null,"errorMessage":"Expected b.shape[0] to be equal to a.shape[0]. Received: a.shape={a.shape}, b.shape={b.shape}","messagePattern":"Expected b\\.shape\\[0\\] to be equal to a\\.shape\\[0\\]\\. Received: a\\.shape=(.+?), b\\.shape=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/ops/linalg.py","lineNumber":637,"sourceCode":"    def __init__(self, rcond=None, *, name=None):\n        super().__init__(name=name)\n        self.rcond = rcond\n\n    def call(self, a, b):\n        return backend.linalg.lstsq(a, b, rcond=self.rcond)\n\n    def compute_output_spec(self, a, b):\n        if len(a.shape) != 2:\n            raise ValueError(\n                f\"Expected a to have rank 2. Received: a.shape={a.shape}\"\n            )\n        if len(b.shape) not in (1, 2):\n            raise ValueError(\n                f\"Expected b to have rank 1 or 2. Received: b.shape={b.shape}\"\n            )\n        m, n = a.shape\n        if b.shape[0] != m:\n            raise ValueError(\n                \"Expected b.shape[0] to be equal to \"\n                \"a.shape[0]. Received: \"\n                f\"a.shape={a.shape}, b.shape={b.shape}\"\n            )\n        if len(b.shape) == 2:\n            k = b.shape[1]\n            x = KerasTensor((n, k), dtype=a.dtype)\n        else:\n            x = KerasTensor((n,), dtype=a.dtype)\n        return x\n\n\n@keras_export([\"keras.ops.lstsq\", \"keras.ops.linalg.lstsq\"])\ndef lstsq(a, b, rcond=None):\n    \"\"\"Return the least-squares solution to a linear matrix equation.\n\n    Computes the vector x that approximately solves the equation\n    `a @ x = b`. The equation may be under-, well-, or over-determined","sourceCodeStart":619,"sourceCodeEnd":655,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/ops/linalg.py#L619-L655","documentation":"Error \"Expected b.shape[0] to be equal to a.shape[0]. Received: a.shape={a.shape}, b.shape={b.shape}\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/ops/linalg.py:637 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}