{"record":{"id":"e409f618c9782f9b","repo":"keras-team/keras","slug":"input-should-have-rank-2-received-input-shape","errorCode":null,"errorMessage":"Input should have rank >= 2. Received: input.shape = {x.shape}","messagePattern":"Input should have rank >= 2\\. Received: input\\.shape = (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/ops/linalg.py","lineNumber":415,"sourceCode":"        return Norm(ord=ord, axis=axis, keepdims=keepdims).symbolic_call(x)\n    x = backend.convert_to_tensor(x)\n    return backend.linalg.norm(x, ord=ord, axis=axis, keepdims=keepdims)\n\n\nclass Qr(Operation):\n    def __init__(self, mode=\"reduced\", *, name=None):\n        super().__init__(name=name)\n        if mode not in {\"reduced\", \"complete\"}:\n            raise ValueError(\n                \"`mode` argument value not supported. \"\n                \"Expected one of {'reduced', 'complete'}. \"\n                f\"Received: mode={mode}\"\n            )\n        self.mode = mode\n\n    def compute_output_spec(self, x):\n        if len(x.shape) < 2:\n            raise ValueError(\n                \"Input should have rank >= 2. Received: \"\n                f\"input.shape = {x.shape}\"\n            )\n        m = x.shape[-2]\n        n = x.shape[-1]\n        if m is None or n is None:\n            raise ValueError(\n                \"Input should have its last 2 dimensions \"\n                \"fully-defined. Received: \"\n                f\"input.shape = {x.shape}\"\n            )\n        k = min(m, n)\n        base = tuple(x.shape[:-2])\n        if self.mode == \"reduced\":\n            return (\n                KerasTensor(shape=base + (m, k), dtype=x.dtype),\n                KerasTensor(shape=base + (k, n), dtype=x.dtype),\n            )","sourceCodeStart":397,"sourceCodeEnd":433,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/ops/linalg.py#L397-L433","documentation":"Qr.compute_output_spec requires the input to have rank >= 2 because QR factorization is defined on matrices (batched matrices allowed). Passing a 1-D vector or scalar raises this ValueError; reshape to at least (m, n) first.","triggerScenarios":"Thrown at keras/src/ops/linalg.py:415 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Reshape the input to at least 2D, e.g. (-1, n)","Check that x is a matrix, not a vector"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}