python
runtime_error
ai_generated
true
IndexError:索引 5 超出轴 0 的范围(大小为 5)
IndexError: index 5 is out of bounds for axis 0 with size 5
ID: python/numpy-index-error-bounds
80%修复率
90%置信度
0证据数
2024-05-30首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
整数索引等于或超过数组长度;差一错误或轴错误。
English
Integer index equals or exceeds array length; off-by-one or wrong axis.
解决方案
-
95% 成功率
if 0 <= i < arr.shape[0]: val = arr[i]
-
85% 成功率
arr.take([i], mode='clip') for clamped access
无效尝试
常见但无效的做法:
-
70% 失败
Silently drops data rows
-
60% 失败
Only fixes the last-index case