Tensorflow | tf.data.Dataset.reduce()
With the help of tf.data.Dataset.reduce()
method, we can get the reduced transformation of all the elements in the dataset by using tf.data.Dataset.reduce()
method.
Syntax : tf.data.Dataset.reduce()
Return : Return combined single result after transformation.
Note :
These given examples will demonstrate the use of new version of tensorflow 2.0, so if you want to run these examples please run the following commands in command prompt.
pip install tensorflow==2.0.0-rc2
Example #1 :
In this example we can see that by using tf.data.Dataset.reduce()
method, we are able to get the reduced transformation of all the elements from the dataset.
import tensorflow as tf
gfg = tf.data.Dataset.from_tensor_slices([ 1 , 2 , 3 , 4 , 5 ])
print (gfg. reduce ( 0 , lambda x, y: x + y).numpy())
|
Output :
15
Example #2 :
import tensorflow as tf
gfg = tf.data.Dataset.from_tensor_slices([[ 5 , 10 ], [ 3 , 6 ]])
print (gfg. reduce ( 0 , lambda x, y: x * y).numpy())
|
Output :
[15, 60]
Last Updated :
03 Oct, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...