【发布时间】:2020-04-13 15:46:28
【问题描述】:
当我尝试测试 .pkl 形式的数据集时,我遇到了这种错误。以下是出现此特定错误的代码部分:
f = open("TP_index_blstm.pkl",'wb')
pickle.dump(result[1], f)
f.close()
#print(type(result[1]))
f_TP = open("./result_analyze/BGRU/TP_filenames.txt","ab+")
for i in range(len(str(result[1]))):
TP_index = result[i]
f_TP.write(str(filenames[TP_index])+'\n')
我不明白为什么会出现这个错误,我是这种错误的新手,请建议我解决这个 IndexError。 result[1] 的类型是 . 出现的错误如下:
Traceback (most recent call last):
File "bgru.py", line 240, in <module>
main(traindataSetPath, testdataSetPath, realtestdataSetPath, weightPath, resultPath, batchSize, maxLen, vectorDim, layers, dropout)
File "bgru.py", line 154, in main
f_TP.write((filenames[TP_index])+'\n')
TypeError: list indices must be integers, not numpy.float64
【问题讨论】:
-
" 结果[1] 的类型是 ." - 是什么?
-
你可能想要
"a",而不是"ab+",作为模式。如果您正在写入str值,并且您根本没有尝试从文件中读取,则不应以二进制模式打开它,因此不需要+。 -
@chepner 当我从中删除 + 时,发生同样的错误......
-
这不是问题的解决方案,只是一个不相关的建议。
-
@Błotosmętek 结果类型 [1] 是
标签: python