用法
@staticmethod
zip(
    datasets, name=None
)参数
- 
datasets数据集的(嵌套)结构。 - 
name(可选。) tf.data 操作的名称。 
返回
- 
Dataset一个Dataset。 
通过将给定的数据集压缩在一起来创建 Dataset。
此方法与 Python 中的内置 zip() 函数具有相似的语义,主要区别在于 datasets 参数可以是 Dataset 对象的(嵌套)结构。此处记录了支持的嵌套机制。
# The nested structure of the `datasets` argument determines the
# structure of elements in the resulting dataset.
a = tf.data.Dataset.range(1, 4)  # ==> [ 1, 2, 3 ]
b = tf.data.Dataset.range(4, 7)  # ==> [ 4, 5, 6 ]
ds = tf.data.Dataset.zip((a, b))
list(ds.as_numpy_iterator())
[(1, 4), (2, 5), (3, 6)]
ds = tf.data.Dataset.zip((b, a))
list(ds.as_numpy_iterator())
[(4, 1), (5, 2), (6, 3)]
# The `datasets` argument may contain an arbitrary number of datasets.
c = tf.data.Dataset.range(7, 13).batch(2)  # ==> [ [7, 8],
                                           #       [9, 10],
                                           #       [11, 12] ]
ds = tf.data.Dataset.zip((a, b, c))
for element in ds.as_numpy_iterator():
  print(element)
(1, 4, array([7, 8]))
(2, 5, array([ 9, 10]))
(3, 6, array([11, 12]))
# The number of elements in the resulting dataset is the same as
# the size of the smallest dataset in `datasets`.
d = tf.data.Dataset.range(13, 15)  # ==> [ 13, 14 ]
ds = tf.data.Dataset.zip((a, d))
list(ds.as_numpy_iterator())
[(1, 13), (2, 14)]
相关用法
- Python tf.compat.v1.data.Dataset.snapshot用法及代码示例
 - Python tf.compat.v1.data.Dataset.random用法及代码示例
 - Python tf.compat.v1.data.Dataset.make_one_shot_iterator用法及代码示例
 - Python tf.compat.v1.data.Dataset.window用法及代码示例
 - Python tf.compat.v1.data.Dataset.unbatch用法及代码示例
 - Python tf.compat.v1.data.Dataset.get_single_element用法及代码示例
 - Python tf.compat.v1.data.Dataset.padded_batch用法及代码示例
 - Python tf.compat.v1.data.Dataset.apply用法及代码示例
 - Python tf.compat.v1.data.Dataset.with_options用法及代码示例
 - Python tf.compat.v1.data.Dataset.cardinality用法及代码示例
 - Python tf.compat.v1.data.Dataset.bucket_by_sequence_length用法及代码示例
 - Python tf.compat.v1.data.Dataset.from_tensors用法及代码示例
 - Python tf.compat.v1.data.Dataset.make_initializable_iterator用法及代码示例
 - Python tf.compat.v1.data.Dataset.batch用法及代码示例
 - Python tf.compat.v1.data.Dataset.take用法及代码示例
 - Python tf.compat.v1.data.Dataset.flat_map用法及代码示例
 - Python tf.compat.v1.data.Dataset.reduce用法及代码示例
 - Python tf.compat.v1.data.Dataset.shard用法及代码示例
 - Python tf.compat.v1.data.Dataset.unique用法及代码示例
 - Python tf.compat.v1.data.Dataset.shuffle用法及代码示例
 
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.compat.v1.data.Dataset.zip。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
