“Got 1 columns instead of …” error in numpy

后端 未结 8 679
傲寒
傲寒 2021-01-17 13:00

I\'m working on the following code for performing Random Forest Classification on train and test sets;

from sklearn.ensemble import RandomForestClassifier
fr         


        
8条回答
  •  清酒与你
    2021-01-17 13:19

    genfromtxt will give this error if the number of columns is unequal.

    I can think of 3 ways around it:

    1. Use the usecols parameter

    np.genfromtxt('yourfile.txt',delimiter=',',usecols=np.arange(0,1434))
    

    However - this may mean that you lose some data (where rows are longer than 1434 columns) - whether or not that matters is down to you.

    2. Adjust your input data file so that it has an equal number of columns.

    3. Use something other than genfromtxt:

    .............like this

提交回复
热议问题