Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何重塑Tensorflow数据集中的数据?_Python_Pandas_Tensorflow_Deep Learning_Reshape - Fatal编程技术网

Python 如何重塑Tensorflow数据集中的数据?

Python 如何重塑Tensorflow数据集中的数据?,python,pandas,tensorflow,deep-learning,reshape,Python,Pandas,Tensorflow,Deep Learning,Reshape,我正在编写一个数据管道,将成批的时间序列和相应的标签输入到需要3D输入形状的LSTM模型中。我目前有以下情况: def split(window): return window[:-label_length], window[-label_length] dataset = tf.data.Dataset.from_tensor_slices(data.sin) dataset = dataset.window(input_length + label_length, shift=la

我正在编写一个数据管道,将成批的时间序列和相应的标签输入到需要3D输入形状的LSTM模型中。我目前有以下情况:

def split(window):
    return window[:-label_length], window[-label_length]

dataset = tf.data.Dataset.from_tensor_slices(data.sin)
dataset = dataset.window(input_length + label_length, shift=label_shift, stride=1, drop_remainder=True)
dataset = dataset.flat_map(lambda window: window.batch(input_length + label_length))
dataset = dataset.map(split, num_parallel_calls=tf.data.AUTOTUNE)
dataset = dataset.cache()
dataset = dataset.shuffle(shuffle_buffer, seed=shuffle_seed, reshuffle_each_iteration=False)
dataset = dataset.batch(batch_size=batch_size, drop_remainder=True)
dataset = dataset.prefetch(tf.data.AUTOTUNE)
在dataset.take(1):x.shape中x,y的
的结果形状是(32,20),其中32是批次大小,20是序列长度,但我需要一个(32,20,1)形状,其中附加维度表示特征


我的问题是,在缓存数据之前,如何在传递到
dataset.map
函数的
split
函数中进行重塑?这很简单。在分割函数中执行此操作

def split(window):
    return window[:-label_length, tf.newaxis], window[-label_length, tf.newaxis, tf.newaxis]

这将返回x数据(32,20,1)的正确形状,但不会返回目标的正确形状。预期的形状是(32,1,1),但它返回的形状是(32),
返回窗口[:-label\u length,tf.newaxis],窗口[-label\u length,tf.newaxis,tf.newaxis]
?我刚刚测试过,它可以工作,谢谢你是的,很抱歉没有意识到你需要目标也有额外的维度。是的,您需要做的就是将
tf.newaxis
添加到标签中。我会更新我的答案