CJ258 2020-02-25 00:01 采纳率: 0%
浏览 2570

求助!!! 帮忙解决:TypeError: only integer scalar arrays can be converted to a scalar index

不多说了,直接上代码,希望大神帮帮!谢谢了~

test_labels[100]

array([0., 0., 0., 0., 1., 0., 0., 0., 0., 0.], dtype=float32)

def plot_images(i,predictions_array,true_label,img):
    predictions_array,true_label,img = predictions_array,true_label,img[i]
    plt.grid(False)
    plt.xticks(range(10))
    plt.yticks([])

    plt.imshow(img)

    predicted_label = np.array(predictions_array)
    if predicted_label == true_label:
        color = 'blue'
    else:
        color = 'red'
#(np.array(class_names)[train_labels[i]])     
    plt.xlabel("{} {:2.0f}% ({})".format(class_names[predicted_label],
                                        100*np.max(predictions_array),
                                        class_names[true_label]),color=color)

def plot_value_array(i,predictions_array,true_label):
    predictions_array,true_label = predictions_array,true_label[i]
    plt.grid(False)
    plt.xticks(range(10))
    plt.yticks([])
    thisplot = plt.bar(range(10), predictions_array, color="#777777")    
    plt.ylim([0, 1])
    predicted_label = np.argmax(predictions_array)

    thisplot[predicted_label].set_color('red')
    thisplot[true_label].set_color('blue')

i = 0
plt.figure(figsize=[6,3])
plt.subplot(1,2,1)
plot_images(i,predictions[i],test_labels,test_images)
plt.subplot(1,2,2)
plot_value_array(i,predictions[i],test_labels)
plt.show()

报错内容:
TypeError Traceback (most recent call last)
in
2 plt.figure(figsize=[6,3])
3 plt.subplot(1,2,1)
----> 4 plot_images(i,predictions[i],test_labels,test_images)
5 plt.subplot(1,2,2)
6 plot_value_array(i,predictions[i],test_labels)

in plot_images(i, predictions_array, true_label, img)
13 color = 'red'
14 #(np.array(class_names)[train_labels[i]])
---> 15 plt.xlabel("{} {:2.0f}% ({})".format(class_names[predicted_label],
16 100*np.max(predictions_array),
17 class_names[true_label]),color=color)

TypeError: only integer scalar arrays can be converted to a scalar index

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-09 19:36
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题