代码部分
c_d = dict(zip(candidate,dist))
cd_sorted = sorted(c_d.items(), key=lambda d:d[1])
print ("\n The person is: " ,cd_sorted[0][0])
dlib.hit_enter_to_continue()
运行出错显示:
Traceback (most recent call last):
File "girl-face-rec.py", line 66, in
print ("\n The person is: " ,cd_sorted[1][5])
IndexError: list index out of range
帮忙看看问题出在哪里?
出错信息是list index out of range,意思是列表索引超出范围,看看你定义的列表索引是多少,很好解决的问题,满意望采纳,谢谢。
cd_sorted访问的时候索引越界了。看看它有什么数据
[1][5]表示数组越界了,表明你的数组数据长度不足,你打印数据看看就明白了
list index out of range列表的索引超过了范围,而你用德烈表是cd_sorted,看看它是不是二维的,事不是空的。
list index out of range,意思是列表索引超出范围 比如你的 list.size()为5,你list[6]就会报这个错
列表索引超出范围了
list index out of range,意思是列表索引超出范围 比如你的 list.size()为5,你list[6]就会报这个错
列表超出索引范围,应该是二维没有第五个元素
列表超出了索引,你返回的是列表,不是二维的吧
cd_sorted这个确定是二维的吗
cd_sorted访问越界,要么是1大于其实际长度, 要么是5大于其实际长度
c_d = dict(zip(candidate,dist))
cd_sorted = sorted(c_d.items(), key=lambda d:d[1])
报错是因为索引超出范围导致, 所以你需要确认你的双份列表是否长度都大于5. 因为zip会取最小的列表长度