ValueError: cannot reshape array of size 3 into shape (1,80)

ValueError: cannot reshape array of size 3 into shape (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_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