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 import tensorflow as tf # using tf.data.Dataset.reduce() method 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 import tensorflow as tf # using tf.data.Dataset.reduce() method gfg = tf.data.Dataset.from_tensor_slices([[5, 10], [3, 6]]) print(gfg.reduce(0, lambda x, y: x * y).numpy()) |
Output :
[15, 60]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Python | Classify Handwritten Digits with Tensorflow
- Introduction to TensorFlow
- Softmax Regression using TensorFlow
- Introduction to Tensor with Tensorflow
- Python | Tensorflow cos() method
- Linear Regression Using Tensorflow
- Python | Tensorflow nn.sigmoid()
- Python | Tensorflow nn.relu() and nn.leaky_relu()
- Python | Tensorflow nn.softplus()
- Python | Tensorflow nn.tanh()
- Python | Creating tensors using different functions in Tensorflow
- ML | Logistic Regression using Tensorflow
- Python | Tensorflow sin() method
- Python | Tensorflow atan() method
- Python | Tensorflow tan() method
- Python | Tensorflow cosh() method
- Python | Tensorflow sinh() method
- Python | Tensorflow asin() method
- Python | Tensorflow acos() method
- Python | Tensorflow reciprocal() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

