{"record":{"id":"bdcaf46310811b5b","repo":"keras-team/keras","slug":"length-of-start-indices-must-match-length-of-sh-bdcaf4","errorCode":null,"errorMessage":"Length of `start_indices` must match length of `shape`. Received: start_indices={start_indices}, shape={shape}","messagePattern":"Length of `start_indices` must match length of `shape`\\. Received: start_indices=(.+?), shape=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/numpy/ops/core.py","lineNumber":362,"sourceCode":"    if reduction is None:\n        inputs[idx] = updates\n    elif reduction == \"add\":\n        np.add.at(inputs, idx, updates)\n    elif reduction == \"max\":\n        np.maximum.at(inputs, idx, updates)\n    elif reduction == \"min\":\n        np.minimum.at(inputs, idx, updates)\n    elif reduction == \"mul\":\n        np.multiply.at(inputs, idx, updates)\n    else:\n        raise ValueError(f\"Unsupported reduction: {reduction}\")\n    return inputs\n\n\ndef slice(inputs, start_indices, shape):\n    # Validate inputs\n    if len(start_indices) != len(shape):\n        raise ValueError(\n            \"Length of `start_indices` must match length of `shape`. \"\n            f\"Received: start_indices={start_indices}, shape={shape}\"\n        )\n\n    # Generate list of indices arrays for each dimension\n    indices = [\n        np.arange(start, start + length)\n        for start, length in zip(start_indices, shape)\n    ]\n\n    # Use np.ix_ to create a multidimensional index array\n    mesh = np.ix_(*indices)\n\n    return inputs[mesh]\n\n\ndef slice_update(inputs, start_indices, updates):\n    # Generate list of indices arrays for each dimension","sourceCodeStart":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/numpy/ops/core.py#L344-L380","documentation":"Validation at the top of the NumPy backend's `slice` op: `start_indices` gives the corner of the region to extract and `shape` its extent, so the two sequences must have one entry per input dimension. If `len(start_indices) != len(shape)` (e.g. a 2D offset paired with a 3D size), the slice specification is ambiguous and the guard rejects it, echoing both arguments.","triggerScenarios":"Thrown at keras/src/backend/numpy/ops/core.py:362 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Make start_indices a sequence with exactly as many elements as shape, one per dimension of `inputs`","Use plain Python lists/tuples for both arguments so their lengths are unambiguous","Build the size list from inputs.ndim (e.g. [inputs.shape[d] - s for d, s in enumerate(start_indices)]) to guarantee consistency"],"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"}