简体   繁体   English

如何使用 keras 将数组重塑为 3d

[英]How to reshape an array to 3d using keras

I have 1260 rows and 2 columns that represent a feature per column (ie 'Open','High') for stock predictions.我有 1260 行和 2 列代表股票预测的每列特征(即“开盘”、“高”)。 I need to reshape this array into the 3D array for input into Nerual Network using LSTM.我需要将此数组重塑为 3D 数组,以便使用 LSTM 输入神经网络。

This is my code so far:到目前为止,这是我的代码:

X_train, y_train = np.array(X_train), np.array(y_train)
X_train = np.reshape(X_train, (X_train.shape[0], X_train.shape[1], 2))

The last line of the code I am confused about what it is telling me.代码的最后一行我对它告诉我的内容感到困惑。 It's meant to put it into a 3D array but it seems like a 2D array to me.它的目的是将它放入一个 3D 数组中,但对我来说它似乎是一个 2D 数组。

How can I feed the network an array (or vector of Open values) and an array of High Values.如何向网络提供数组(或开放值向量)和高值数组。

I assume X_train.shape is a 2D tensor, if you want to make it 3D you can use np.expand_dims我假设X_train.shape是一个 2D 张量,如果你想使它成为 3D 你可以使用np.expand_dims

Example例子

arr = np.random.randint(0,5,(3,3))

array([[3, 4, 1],
       [1, 0, 1],
       [4, 4, 2]])

arr.shape = (3,3)
reshape_arr = np.np.expand_dims(arr, -1)
reshape_arr.shape = (3,3,1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM