IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boo

标签: 机器学习及深度学习  python  机器学习  深度学习  神经网络

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.")

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

版权声明:本文为weixin_44033210原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_44033210/article/details/105539823

智能推荐

numpy.newaxis详解

numpy.newaxis numpy.newaxis的工作方式及适用场合 简单地说,newaxis的作用是给现有的数组增加一个维度。例如: 1维数组将变为2维数组 2维数组将变为3维数组 3维数组将变为4维数组 4维数组将变为5维数组 等等。 我们在这里利用图示的方法解释一维数组通过添加新维度变为二维数组的过程: 一维数组在列方向(axis=0)进行广播变为二维数组: 一维数组在行方向(axis...

TypeError: slice indices must be integers or None or have an __index__ method解决方法

在pycharm调试程序时遇到了这样的错误,下面分析一下错误原因以及解决方法: 该错误的意思是 类型错误:切片索引必须是整数或无或有一个_index__方法 1.错误原因:程序在运行过程中,出现浮点数情形,与源码冲突 解决方法:将数据强制转换为int整型类型。即int(数据) 同时将代码中的除法运算(/)改为 // 例如: 2.错误原因:statsmodels的库版本过低,报错 解决方法: #1 ...

TypeError: slice indices must be integers or None or have an __index__ method原因分析及解决办法

TypeError: slice indices must be integers or None or have an __index__ method 目标 1. 错误提示 2. 错误原因 3. 解决方案 目标 今天给大家带来Python程序中报错TypeError: slice indices must be integers or None or have an __index__ met...

Error:Cause: greenDAO supports only Java and Android projects. None of the corresponding plugins hav

在AndroidStudio导入一个新Module的时候,导入的Module没有显示手机图标,且和其他Module显示的是java项目咖啡的图标 这应该是导入GreenDao插件的时候是出错了,我的是在Project的Build.gradle文件里按照别人教程注入了这个 解决: 把这一行去掉就行了,再重新Rebuild Project 就可以了 我的Project的build配置是: 我的Modu...

JPA更新报错:Modifying queries can only use void or int/Integer as return type!

问题:jpa手写更新语句时,返回值必须为void 或者 int/Integer。笔者这里是返回bool,所以报错 错误代码: 修改后代码: 注解说明 测试用例:操作成功返回1;失败返回0...

猜你喜欢

Python:Python3错误提示TypeError: slice indices must be integers or None or have an __index__ method解决办法

Python:Python3错误提示TypeError: slice indices must be integers or None or have an __index__ method解决办法 在执行Python 3脚本时,报错:TypeError: slice indices must be integers or None or have an __index__ method,报错位置...

两类和float与int两种数据类型相关的两种错误integer argument expected和slice indices must be integersor None or None or

TypeError: integer argument expected, got float与TypeError: slice indices must be integers or None or None or have an index method 在做opencv相关图像处理时,遇到的一些问题,其中之一是 然后就出现了以下错误 或者该错误 但总之 ,这两种错误均为同一类,只因结果所要的...

VUE给动态生成的el-checkbox添加v-model

需求描述:根据返回的数据,页面动态for循环添加el-checkbox,动态绑定v-model; html代码: tabList数据格式: 之前的错误做法: 开始以为这样就可以了,毕竟在el-checkbox上用item.status绑定v-model,后面发现checkbox点击的时候并没有更新; 解决方案: 官方文档...

[UE4]蓝图和C++调用自定义函数

1、C++自定义方法,蓝图调用 UFUNCTION宏是处理将C++函数暴露给反射系统的一些事情,参数BlueprintCallable意味着这个函数可以在蓝图中调用,而后面的目录是必须有的,这样在蓝图中右键点击的时候,我们就可以根据这个目录找到我们需要的函数。 2、蓝图定义方法,C++调用 当我们在蓝图中定义了一系列操作后,我们也想用C++调用,我们利用BlueprintImplementable...

Redis--2.Jedis的介绍和使用

一.概念 Jedis是Redis官方推荐使用的的一个Java连接开发的工具(中间件)。 Jedis主要是集成了redis的一些命令操作,封装了redis的java客户端。 使用Jedis操作Redis数据库,就相当于使用JDBC操作sql_server、Mysql数据库。 二.两种连接方式 1.Jedis对象直连Redis Jedis对象直连方式可以分为五个步骤: 1、导入Jedis的jar包 2...