Create a Dataset by zipping together an array, dict, or nested
structure of Datasets (and perhaps additional constants).
The underlying datasets must provide elements in a consistent order such that
they correspond.
The number of elements in the resulting dataset is the same as the size of
the smallest dataset in datasets.
The nested structure of the datasets argument determines the
structure of elements in the resulting iterator.
Note this means that, given an array of two datasets that produce dict
elements, the result is a dataset that produces elements that are arrays
of two dicts:
Zip an array of datasets:
console.log('Zip two datasets of objects:'); constds1 = tf.data.array([{a:1}, {a:2}, {a:3}]); constds2 = tf.data.array([{b:4}, {b:5}, {b:6}]); constds3 = tf.data.zip([ds1, ds2]); awaitds3.forEachAsync(e=>console.log(JSON.stringify(e)));
// If the goal is to merge the dicts in order to produce elements like // {a: ..., b: ...}, this requires a second step such as: console.log('Merge the objects:'); constds4 = ds3.map(x=> {return {a:x[0].a, b:x[1].b}}); awaitds4.forEachAsync(e=>console.log(e));
Create a
Dataset
by zipping together an array, dict, or nested structure ofDataset
s (and perhaps additional constants). The underlying datasets must provide elements in a consistent order such that they correspond.The number of elements in the resulting dataset is the same as the size of the smallest dataset in datasets.
The nested structure of the
datasets
argument determines the structure of elements in the resulting iterator.Note this means that, given an array of two datasets that produce dict elements, the result is a dataset that produces elements that are arrays of two dicts:
Zip an array of datasets:
Zip a dict of datasets: