TypeError:only integer scalar arrays can be converted to a scalar index.[Python Code ]

一、报错截图:

TypeError:only integer scalar arrays can be converted to a scalar index.[Python Code ]_第1张图片

二、定位出错的代码:

def test_batch(path):
    model = Model()
    model.load()
    index = 0
    img_list, label_list, counter = read_file(path)
    # print(img_list.shape[1:])
    for img in img_list:
        # plt.imshow(img[::1], cmap='gray')
        # plt.show()
        label_index, prob = model.predict(img)
        # 判断label_index是否存在
        if label_index != -1:
            index += 1
            name_list = read_file_name_list('C:/Users/tianr/Desktop/Experiment_Data/gray_breastShear_raw(150)')
            print(name_list)
            print(name_list[label_index)

        else:
            print("Don't know this person")

    return index

经调试,name_list是列表,这一点没有错是可以进行索引的,label_index也是int64类型。按说没有错,困惑许久。既然列表不能进行索引,将列表转为数组再进行索引试一试看。

TypeError:only integer scalar arrays can be converted to a scalar index.[Python Code ]_第2张图片

三、成功打印,代码调通

TypeError:only integer scalar arrays can be converted to a scalar index.[Python Code ]_第3张图片

你可能感兴趣的:(Debug)