IndexError:使用ConvertOneHot对标量变量的索引无效

时间:2016-06-16 15:40:47

标签: python-2.7 debugging error-handling scipy data-science

data = np.genfromtxt('TrainingSet.csv',invalid_raise=False)  # Training data
test_data = np.genfromtxt('TestSet.csv',invalid_raise=False)  # Test data


def convertOneHot(inp):
    y=np.array([int(i[0]) for i in inp])
    y_onehot=[0]*len(y)
    for i,j in enumerate(y):
        y_onehot[i]=[0]*(y.max() + 1)
        y_onehot[i][j]=1
    return (y,y_onehot)


x_train=np.ndarray([ in[1::] for i in data])
y_train,y_train_onehot = convertOneHot(data)

x_test=np.ndarray([ i[1::] for i in test_data])
y_test,y_test_onehot = convertOneHot(test_data)

My error message is as follows:

我已经看到在其他线程中解决了此错误的问题,但是我尝试过的解决方法或修复程序似乎都不适用于我。

0 个答案:

没有答案