首页 > 解决方案 > timeseries_dataset_from_array 产生 4d 数组

问题描述

我正在使用timeseries_dataset_from_arrayfromtensorflow.keras.preprocessingLSTM模型生成时间序列。

我的输入data是一个 2Dnumpy.ndarray的 shape (2500, 9)

我正在创建这样的时间序列:

        input_dataset = timeseries_dataset_from_array(data=data, targets=None, sequence_length=70, batch_size=1)

然后我转换input_dataset为一个 numpy 数组:

input_as_list = list(input_dataset)
input_np = np.stack(input_as_list) # same output with np.asarray

然而 的形状等input_as_listinput_np4D: (2500, 1, 70, 9)

为了绕过我正在重塑input_np 为 3D 的问题。由于batch_size设置为 1,这非常简单:

input_np_3d = np.reshape(input_np, [input_np.shape[0], input_np.shape[2], input_np.shape[3]])

然而这感觉不对。默认情况下不应该timeseries_dataset_from_array生成 3D 时间序列吗?我错过了什么?

标签: pythontensorflownumpy-ndarraytf.keras

解决方案


推荐阅读