• 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:');
    const ds1 = tf.data.array([{a: 1}, {a: 2}, {a: 3}]);
    const ds2 = tf.data.array([{b: 4}, {b: 5}, {b: 6}]);
    const ds3 = tf.data.zip([ds1, ds2]);
    await ds3.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:');
    const ds4 = ds3.map(x => {return {a: x[0].a, b: x[1].b}});
    await ds4.forEachAsync(e => console.log(e));

    Zip a dict of datasets:

    const a = tf.data.array([{a: 1}, {a: 2}, {a: 3}]);
    const b = tf.data.array([{b: 4}, {b: 5}, {b: 6}]);
    const c = tf.data.zip({c: a, d: b});
    await c.forEachAsync(e => console.log(JSON.stringify(e)));

    Type Parameters

    Parameters

    • datasets: DatasetContainer

    Returns Dataset<O>

    Doc

Generated using TypeDoc