【发布时间】:2020-10-12 09:03:42
【问题描述】:
尝试从 DATASET 中拆分要素和标签时出现错误。代码如下:
print("Persiapan data")
#Split features and label from DATASET
X = [] #features
Y = [] #labels
x_train,y_train=[],[]
for features,label in vektor_input:
X.append(features)
Y.append(label)
#Split X,Y to train and test
x_train,x_test,y_train,y_test = train_test_split(X, Y, train_size=0.7)
x_train = np.array(x_train)
x_train = np.reshape(x_train, (x_train.shape[0], 1, x_train.shape[1]))
x_test = np.array(x_test)
x_test = np.reshape(x_test, (x_test.shape[0], 1, x_test.shape[1]))
print("Ukuran x_train :",len(x_train))
print("Ukuran x_test :",len(x_test))
错误显示。我是 python 新手。请帮忙,我已尝试修复它,但出现了一些错误并卡住了。
IndexError Traceback (most recent call
last) <ipython-input-12-cd5441347f88> in <module>
12
13 x_train = np.array(x_train)
---> 14 x_train = np.reshape(x_train, (x_train.shape[0], 1, x_train.shape[1]))
15 x_test = np.array(x_test)
16 x_test = np.reshape(x_test, (x_test.shape[0], 1, x_test.shape[1]))
IndexError: tuple index out of range
【问题讨论】:
-
x_train和y_train是数组,对吧?所以形状只有一维而不是 2。 -
是的,就是数组。好的,我试试
标签: python numpy tensorflow keras recurrent-neural-network