m0_61104322
2022-04-22 15:50
采纳率: 88.2%
浏览 278

IndexError: index 8000 is out of bounds for axis 0 with size 8000

用了一个新的数据集,跑的也是之前跑过的代码,可是出现了问题:

# coding=utf-8
import pandas as pd
import numpy as np
import fasttext
from sklearn import metrics

with open('train_abstract.txt','w',encoding='utf-8') as f:
    for i in range(len(X_train.todense())):
        str1 = str(X_train.todense()[i])+"\t"+"__label__"+str(y_train.values[i])+'\n'
        f.write(str1)

with open('test_abstract.txt','w',encoding='utf-8') as f:
    for i in range(len(X_test)):
        str1 = str(X_test.values[i])+"\t"+"__label__"+str(y_test.values[i])+'\n'
        f.write(str1)

IndexError                                Traceback (most recent call last)
<ipython-input-38-1b98cdb96387> in <module>()
      7 with open('train_abstract.txt','w',encoding='utf-8') as f:
      8     for i in range(len(X_train.todense())):
----> 9         str1 = str(X_train.todense()[i])+"\t"+"__label__"+str(y_train.values[i])+'\n'
     10         f.write(str1)
     11 

IndexError: index 8000 is out of bounds for axis 0 with size 8000

麻烦大家帮忙解答一下,谢谢!

3条回答 默认 最新

相关推荐 更多相似问题