{"record":{"id":"88cf7377f067c38f","repo":"keras-team/keras","slug":"the-number-of-dimensions-in-start-indices-must-m","errorCode":null,"errorMessage":"The number of dimensions in `start_indices` must match the number of dimensions in `inputs`. Received start_indices={start_indices} and inputs.shape={inputs.shape}","messagePattern":"The number of dimensions in `start_indices` must match the number of dimensions in `inputs`\\. Received start_indices=(.+?) and inputs\\.shape=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/ops/core.py","lineNumber":448,"sourceCode":"class Slice(Operation):\n    def __init__(self, shape, *, name=None):\n        super().__init__(name=name)\n        self.shape = shape\n\n    def call(self, inputs, start_indices):\n        return backend.core.slice(inputs, start_indices, self.shape)\n\n    def compute_output_spec(self, inputs, start_indices):\n        if len(self.shape) != len(inputs.shape):\n            raise ValueError(\n                \"The number of dimensions in `inputs` must match the number of \"\n                f\"dimensions in `shape`. Received inputs.shape={inputs.shape} \"\n                f\"and shape={self.shape}\"\n            )\n        if hasattr(start_indices, \"__len__\") and len(start_indices) != len(\n            inputs.shape\n        ):\n            raise ValueError(\n                \"The number of dimensions in `start_indices` must match the \"\n                \"number of dimensions in `inputs`. Received \"\n                f\"start_indices={start_indices} and inputs.shape={inputs.shape}\"\n            )\n\n        final_shape = []\n        for i, (input_dim, slice_dim) in enumerate(\n            zip(inputs.shape, self.shape)\n        ):\n            if slice_dim != -1:\n                final_shape.append(slice_dim)\n            elif isinstance(start_indices, KerasTensor) or input_dim is None:\n                final_shape.append(None)\n            else:\n                final_shape.append(input_dim - start_indices[i])\n        return KerasTensor(final_shape, dtype=inputs.dtype)\n\n","sourceCodeStart":430,"sourceCodeEnd":466,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/ops/core.py#L430-L466","documentation":"start_indices must list a start offset for every dimension of inputs. Passing fewer or more indices than inputs.ndim makes the slice target ambiguous.","triggerScenarios":"keras.ops.slice(x, (0, 0), ...) on a 3D tensor, or passing an int to a multi-dim tensor","commonSituations":"Writing generic cropping code that assumes rank 2 for rank 3+ tensors","solutions":["Pass a tuple with exactly inputs.ndim entries","Build start_indices dynamically: (0,) * x.ndim"],"exampleFix":"# before\nkeras.ops.slice(x, 0, (2,))  # x.ndim == 3\n\n# after\nkeras.ops.slice(x, (0, 0, 0), (2, 2, 2))","handlingStrategy":"validation","validationCode":"if hasattr(start_indices, '__len__'):\n    assert len(start_indices) == len(x.shape)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass one start index per input dimension","Use a tuple/list of ints for start_indices"],"tags":["keras","ops","slice","indices"],"backgroundTag":"shape-mismatch-between-tensors","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}