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 一道python难题2
  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备