Some methods can also be used to merge datasets together. The two most straightforward ones are .concatenate(dataset) and the static .zip(datasets) (refer to the documentation at https://www.tensorflow.org/api_docs/python/tf/data/Dataset). The former concatenates the samples of the dataset provided with those of the current one, while the latter combines the dataset's elements into tuples (similar to Python's zip()) as follows:
d1 = tf.data.Dataset.range(3)
d2 = tf.data.Dataset.from_tensor_slices([[4, 5], [6, 7], [8, 9]])
d = tf.data.Dataset.zip((d1, d2))
# d will return [0, [4, 5]], [1, [6, 7]], and [2, [8, 9]]
Another method often used to merge data from different sources is .interleave(map_func, cycle_length, block_length, ...) (refer to the documentation at https://www.tensorflow.org/api_docs/python/tf/data/Dataset#interleave). This applies the map_func function to the elements of the datasets and interleaves the results. Let's now go back to the...