Python报错:IndexError: index 0 is out of bounds for axis 0 with size 0

Python报错:

IndexError: index 0 is out of bounds for axis 0 with size 0

原因:
索引超出了列表的长度。
eg1:

import numpy as np
a = np.empty(1)
print(a[1])
# IndexError: index 1 is out of bounds for axis 0 with size 1

eg2:

import numpy as np
a = np.empty(3)
print(a[5])
# IndexError: index 5 is out of bounds for axis 0 with size 3

解决方法:
检查是自己的索引错了, 还是数组长度定义错了。

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
乘风的头像乘风管理团队
上一篇 2023年7月13日
下一篇 2023年7月13日

相关推荐