IndexError: list index out of range
list所用超出问题
核心:list索引是从0开始
list1 = [1, 2, 3, 4, 5, 6]
#list1的索引是从0开始的,因此要取到6就会超出索引
print(list1[6])
报错
Traceback (most recent call last):
File "", line 5, in <module>
print(list1[6])
IndexError: list index out of range
在图像分类领域中,对于有监督学习中数据处理时,遇到有排除未标记的标签是后要分情况
一:
label=[0, 1, 2, 3, 4, 5]
label = label-1
label = [1, 2, 3, 4, 5, 255]
#建立label - 1长度的空列表然后追加
二:
label=[0, 1, 2, 3,4, 5]
label = label-1
label = [-1, 0, 1, 2, 3, 4]
#建立label 对应长度的空列表追加
对于ndarray格式追加后,出现的情况有一个空list,因此使用列表推导式将空list删掉。
ground = [[], [1, 2, 3], [2,3,4], [5, 6 ,3]]
ground = [i for i in ground if i !=[]]
2085

被折叠的 条评论
为什么被折叠?



