吴恩达深度学习课后编程作业IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and i

吴恩达深度学习课后编程作业出现的错误 IndexError: only integers, slices (" : “), ellipsis (”…"), numpy.newaxis (“None”) and integer or boolean arrays are valid indices

出现的这个错误是数据类型错误,错误如下图所示

在这里插入图片描述

找到所在错误行所用的数据

在这里插入图片描述

然后查看是哪个数据错误

注释错误的哪一行,并将所有的单个数据输出
运行,找出错误数据

在这里插入图片描述

这个数据中还含有数据,对其进行分离,并输出其类型。

在这里插入图片描述

发现这个数据为numpy.float64类型,但是Python中的list[i],其中的i只能是int型,所以错误在这里,所以只需要将其强换为int。

在这里插入图片描述

只需加int()。

# Example of a picture that was wrongly classified.
index = 1
plt.imshow(test_set_x[:,index].reshape((num_px, num_px, 3)))
#print(str(test_set_y[0,index]))
#print(classes[d["Y_prediction_test"][0,index]].decode("utf-8"))

#print(d["Y_prediction_test"][0,index])

#type(d["Y_prediction_test"][0,index])
print ("y = " + str(test_set_y[0,index]) + ", you predicted that it is a \"" + classes[int(d["Y_prediction_test"][0,index])].decode("utf-8") +  "\" picture.")

此文章只提供一种找错误的思路

  • 18
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值