Python 3.x numpy数组:元组索引超出范围

Python 3.x numpy数组:元组索引超出范围,python-3.x,export-to-csv,google-colaboratory,Python 3.x,Export To Csv,Google Colaboratory,问题从下面的代码开始 重塑为二维以csv格式保存 也许你能做的是以下几点 创建一个csv文件,其中列40个来自X的第二维度的值,以及Y值 行将首先是训练数据,然后是测试数据 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]))

问题从下面的代码开始

重塑为二维以csv格式保存
也许你能做的是以下几点

创建一个csv文件,其中列
40个来自X的第二维度的值,以及Y值
行将首先是训练数据,然后是测试数据

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
输出数据形状将为


(8732,41)

数组的原始形状是什么?发布错误输出numpy数组的齿形\u train.shape,x\u test.shape,y\u train.shape,y\u test.shape是((7895,40),(837,40),(7895,),(837,))形成的错误是:索引器回溯(最近一次调用最后一次)in()--->1 x\u train\u 2d=np.reformate(x\u train,(x_-train.shape[0],x_-train.shape[1]*x_-train.shape[2])2 x_-test\u 2d=np.重塑(x_-test,(x_-test.shape[0],x_-test.shape[1]*x_-test.shape[2])3 x_-train\u-2d shape,x_-test\u-2d.shape索引器:元组索引超出范围输出形状应该是什么。
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
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=',')