2021-01-29

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 !=[]]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值