[英]how can i get 1dimension to 3dimension reshape?
here is my code 这是我的代码
def create_dataset(signal_data, look_back=1):
dataX, dataY = [], []
for i in range(len(signal_data) - look_back):
dataX.append(signal_data[i:(i + look_back), 0])
dataY.append(signal_data[i + look_back, 0])
return np.array(dataX), np.array(dataY)
look_back = 20
...
train_size = int(len(data) * 0.80)
test_size = len(data) - train_size
train = data[0:train_size]
test = data[train_size:len(data)]
x_train, y_train = create_dataset(train, look_back)
x_test, y_test = create_dataset(test, look_back)
then x_train
shape is (62796, 20) and y_train
shape is(62796,) 那么x_train
形状为(62796,20)和y_train
形状为(62796,)
I use this data to LSTM 我将此数据用于LSTM
so, reshape x_train = np.reshape(x_train, (x_train.shape[0], x_train.shape[1], 1))
is done 因此,完成了重塑x_train = np.reshape(x_train, (x_train.shape[0], x_train.shape[1], 1))
(now x_train.shape
is (62796, 20, 1) ) (现在x_train.shape
是(62796,20,1))
but y_train
shape is (62796,) So, i can't reshape 1D -> 3D 但是y_train
形状是(62796,)所以,我无法重塑1D-> 3D
how can i y_train
reshape 1D ->3D 我如何y_train
重塑1D-> 3D
i want y_train shape as (62796, 20, 1) because want to LSTM return_sequences=True
parameter 我想要y_train形状为(62796,20,1)因为要LSTM return_sequences=True
参数
Is that what you're looking for? 那是您要找的东西吗?
y_train = np.ones(100)
print(y_train.shape) #prints (100,)
y_train = y_train.reshape(-1,1,1)
print(y_train.shape) # prints (100,1,1)
EDIT: Final solution, after brief discussion in comments: 编辑:最终解决方案,经过简短的评论讨论:
y_train=np.repeat(y_train.reshape(-1,1), 20, axis=1).reshape(-1,20,1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.