【发布时间】:2017-11-27 09:37:24
【问题描述】:
我有两个文本文件,每个文件有 10 个值。现在我想将这 10 个值作为两个列表包含在一个列表中并访问列表列表的索引。但问题是我收到一条错误消息,“列表索引必须是整数,而不是元组”。任何建议将不胜感激。
在我拥有的第一个文件中 0.001 0.017 0.07 0.09 0.05 0.02 0.014 0.014 0.021 0.033
在我的第二个文件中
0.001 0.01 0.0788 0.09 0.0599 0.0222 0.014 0.01422 0.0222 0.033
import numpy as np
d=[]
one = np.loadtxt('one.txt')
two=np.loadtxt('two.txt')
d.append(one)
d.append(two)
#I get this error "list indices must be integers, not tuple ", when
# I try to access the index of my lists inside the list
print (d[0,:])
【问题讨论】:
-
试试
d = np.array([one, two])列表不允许多维索引,但numpy数组可以。