m0_61104322 2022-04-22 15:50 采纳率: 90.3%
浏览 2185
已结题

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条回答 默认 最新

  • CSDN专家-sinJack 2022-04-22 16:29
    关注

    IndexError: index 8000 is out of bounds for axis 0 with size 8000
    是指列表出现问题,应该是列表为空或者列表长度为8000,索引值为8000时导致越界了。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 4月30日
  • 已采纳回答 4月22日
  • 创建了问题 4月22日