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

注:仅仅为了自己记录
该错误是索引超出了列表的长度的,比如创建了长度为1的数组a,而我的索引为在a[1]:

import numpy as np
a = np.empty(1)
print(a[1])

就会报错:

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

再比如我创建了长度为3的数组a, 而我的索引为a[5]:

import numpy as np
a = np.empty(3)
print(a[5])

就会报错:

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

(axis 0:表示是一维数组)
所以这时候就回去检查是自己的索引错了, 还是数组长度定义错了。

猜你喜欢

转载自blog.csdn.net/weixin_44493244/article/details/105968388