numpy数组:元组索引超出范围


#converting the lists into numpy arrays
x_train=np.array(x_train)
x_test=np.array(x_test)
y_train=np.array(y_train)
y_test=np.array(y_test)
x_train.shape,x_test.shape,y_train.shape,y_test.shape

问题从下面的代码开始

整形为2d以csv格式保存

x_train_2d=np.reshape(x_train,(x_train.shape[0],x_train.shape[1]*x_train.shape[2]))
x_test_2d=np.reshape(x_test,(x_test.shape[0],x_test.shape[1]*x_test.shape[2]))
x_train_2d.shape,x_test_2d.shape

您可能可以执行以下操作。

创建列为40 values from second dimension of X, and Y value的csv文件行将首先是训练数据,然后是测试数据

data_train = np.c_[x_train, y_train]
data_test = np.c_[x_test, y_test]
data = np.r_[data_train, data_test]
print(data.shape)
np.savetxt('filename.csv', data, delimiter=',')

输出数据形状将为

(8732, 41)

最新更新