tf.dataset.reduce code example
Example: what is tf.data.dataset.reduce()
import tensorflow as tf
data = tf.data.Dataset.from_tensor_slices([1, 2, 3, 4, 5])
print(data.reduce(0, lambda x, y: x + y).numpy())
>> 15
print(data.reduce(1, lambda x, y: x + y).numpy())
>>16
import tensorflow as tf
data = tf.data.Dataset.from_tensor_slices([[5, 10], [3, 6]])
print(data.reduce(0, lambda x, y: x * y).numpy())
>>[0 0]
print(data.reduce(1, lambda x, y: x * y).numpy())
>>[15 60]
print(data.reduce(2, lambda x, y: x * y).numpy())
>>[30 120]