代码先锋网 代码片段及技术文章聚合

list indices must be integers or slices, not tuple解决方案-python学习笔记

技术标签: Python  python  数据分析  numpy

原因:多个[]的数组之间没加,逗号

image.png

源码:

import numpy as np

a = np.array([[1,2][3,4]])
print(a)

报错:

TypeError: list indices must be integers or slices, not tuple

修改方法: 在[1,2]后面加个英文逗号,

import numpy as np

a = np.array([[1,2],[3,4]])
print(a)


 

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

智能推荐

python-TypeError: list indices must be integers or slices, not tuple 报错解决方案

问题描述 在取矩阵某一列时会出现报错,例如执行如下代码: 出现报错:TypeError: list indices must be integers or slices, not tuple 这是因为此时矩阵存储在列表(list)中,而列表中的每一个元素大小可能不同,因此不能直接取其某一列进行操作 解决方案 可以利用numpy.array函数将其转变为标准矩阵,再对其进行取某一列的操作: 可以得到...

list indices must be integers or slices, not list

for i in lines: for j in lines: i and j iterate over the elements of lines, not the indices. That means i and j are always lists, entire lines of numbers. If you want to go over the indices (usually y...

list indices must be integers or slices, not str

原代码: 运行时报错: list indices must be integers or slices, not str 解决方案:由于 username = form.changed_data[‘username’]中的changed_data错误导致,应该为:cleaned_data...

TypeError: list indices must be integers or slices, not str

在 利用BeautifulSoup爬取网址的时候总是遇到TypeError: list indices must be integers or slices, not str 部分的代码是这样的 准备提取的url如下图所示 后来发现是系统把 soup.find_all(“img”,“origin_image zh-lightbox-thumb lazy&rdqu...

TypeError: list indices must be integers or slices, not float

原因: 说明中间传递参数中有浮点数。这是刚刚写的代码中的错误 我的代码: 改正后的代码:  ...

猜你喜欢

TypeError: list indices must be integers or slices, not str

检查是不是url错了,或者请求类型是不是错误,如get类型或者post类型错误...

TypeError: list indices must be integers or slices, not str

原因:json以键值对方式存储信息,但本例中: progressive下的多个值值是以列表方式存储 错误代码: 改为:...

“TypeError: list indices must be integers or slices, not str”报错的解决方案

在处理一个形式类似上述list的时候,想将list中的string处理成首尾无空格、且全部大写的统一形式,方便后续进行排序,按上述方式运行时产生"TypeError: list indices must be integers or slices, not str" 经查询后发现下述方法可以解决,确实是以前没有注意过这个问题:...

处理tuple indices must be integers or slices, not str

x=input() X=(‘零’,‘一’,‘二’,‘三’,‘四’,‘五’,‘六’,‘七’,‘八’,‘九’); for i in x:## 标题 print(X[...

1118 chapter17 &18

使用 modelr 包对R包中的建模函数进行包装,使其可以支持管道操作 找出最佳模型“牛顿-拉夫逊搜索” → optim() 拟合线性的工作 lm() sim1_mod <- lm(y~x, data = sim1) 模型可视化 使用 modelr::data_grid()生成分布均匀的数值网络 使用modelr::add_predictions()添加预测...