在将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_1
和X_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_1
10080 个样本,其余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_2
80 个样本,其余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