当前位置: 代码迷 >> 综合 >> TypeError: list indices must be integers or slices, not numpy.float64
  详细解决方案

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

热度:17   发布时间:2023-12-15 17:04:40.0

报错: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

 

new_idx = list(np.linspace(0, imgs_num, target_len+1))

 

  相关解决方案