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:文章来源:https://www.toymoban.com/news/detail-531956.html
import numpy as np
a = np.empty(3)
print(a[5])
# IndexError: index 5 is out of bounds for axis 0 with size 3
解决方法:
检查是自己的索引错了, 还是数组长度定义错了。文章来源地址https://www.toymoban.com/news/detail-531956.html
到了这里,关于Python报错:IndexError: index 0 is out of bounds for axis 0 with size 0的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!