值错误:无法将大小为 3 的数组调整为形状 (1,80)



在将CNN模型拟合到我的数据时,它捕获了错误:

161         X = X.reshape([X.shape[0], X.shape[1],1])
162         X_train_1 = X[:,0:10080,:]
--> 163         X_train_2 = X[:,10080:10160,:].reshape(1,80)
ValueError: cannot reshape array of size 3 into shape (1,80)

输入数据由X_train_1(形状 1, 10080 的每个样本)和X_train_2(形状 1, 80 的每个样本)组成。X_train_1X_train_2连接以形成形状1, 10160的样本大小。size 3指的是什么?

尝试使用以下两个不同的n值:

import numpy as np
n = 10160
#n = 10083
X = np.arange(n).reshape(1,-1)
np.shape(X)
X = X.reshape([X.shape[0], X.shape[1],1])
X_train_1 = X[:,0:10080,:]
X_train_2 = X[:,10080:10160,:].reshape(1,80)
np.shape(X_train_2)

如果您无法确定X长度为 10160,我建议使用以下解决方案之一:

X_train_110080 个样本,其余X_train_2

X = X.reshape([X.shape[0], X.shape[1],1])
X_train_1 = X[:,0:10080,:] # X_train_1 with 10080 samples
X_train_2 = X[:,10080:,:].reshape(1,-1) # X_train_2 with the remaining samples

或者X_train_280 个样本,其余X_train_1

X = X.reshape([X.shape[0], X.shape[1],1])
X_train_1 = X[:,0:-80,:] # X_train_1 with the remaining samples
X_train_2 = X[:,-80:,:].reshape(1,80) # X_train_2 with 80 samples

相关内容

  • 没有找到相关文章

最新更新