{"record":{"id":"75d5a6dbb6ac76ca","repo":"rohitg00/ai-engineering-from-scratch","slug":"index-ind-out-of-range-for-axis-i-with-size-s","errorCode":null,"errorMessage":"Index {ind} out of range for axis {i} with size {self._shape[i]}","messagePattern":"Index (.+?) out of range for axis (.+?) with size (.+?)","errorType":"exception","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"phases/01-math-foundations/12-tensor-operations/code/tensors.py","lineNumber":80,"sourceCode":"        return len(self._shape)\n\n    @property\n    def size(self):\n        return len(self._data)\n\n    @property\n    def strides(self):\n        return self._strides\n\n    def _flat_index(self, indices):\n        if len(indices) != len(self._shape):\n            raise IndexError(\n                f\"Expected {len(self._shape)} indices, got {len(indices)}\"\n            )\n        idx = 0\n        for i, (ind, stride) in enumerate(zip(indices, self._strides)):\n            if ind < 0 or ind >= self._shape[i]:\n                raise IndexError(\n                    f\"Index {ind} out of range for axis {i} with size {self._shape[i]}\"\n                )\n            idx += ind * stride\n        return idx\n\n    def __getitem__(self, indices):\n        if not isinstance(indices, tuple):\n            indices = (indices,)\n        if len(indices) == len(self._shape):\n            return self._data[self._flat_index(indices)]\n        raise IndexError(\"Partial indexing not supported in this basic implementation\")\n\n    def __setitem__(self, indices, value):\n        if not isinstance(indices, tuple):\n            indices = (indices,)\n        self._data[self._flat_index(indices)] = value\n\n    def reshape(self, new_shape):","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/01-math-foundations/12-tensor-operations/code/tensors.py#L62-L98","documentation":"Error \"Index {ind} out of range for axis {i} with size {self._shape[i]}\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at phases/01-math-foundations/12-tensor-operations/code/tensors.py:80 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":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}