TypeError: list indices must be integers or slices, not numpy.float64

报错:TypeError: list indices must be integers or slices, not numpy.float64

代码:

new_idx = np.linspace(0, imgs_num, target_len+1)
int_idx = [round(i) for i in new_idx]
sub_list = [imgs_list[j] for j in new_idx]

原因: np.linspace生成的是numpy数组,不是List,需要先转换为list才能使用里面的元素做为index

发布了202 篇原创文章 · 获赞 80 · 访问量 30万+

猜你喜欢

转载自blog.csdn.net/qxqxqzzz/article/details/104939993