NumPy | Python Methods and Functions

With the

method, we can get a shorthand transformation of all elements in the dataset using **tf.data.Dataset.reduce()** ` tf.data.Dataset. reduce () `

.

Syntax:`tf.data.Dataset.reduce ()`

Return:Return combined single result after transformation.

** Notes: **

These examples will demonstrate the use of the new version of tensorflow 2.0, therefore, if you want to run these examples, run the following commands on the command line.

pip install tensorflow == 2.0.0-rc2

** Example # 1: **

In this example, we can see that using ` tf.data.Dataset.reduce () `

we can get a reduced transformation of all elements from the dataset.

` `

` ` ` # import tensor by current `

` import `

` tensorflow as tf `

` # using the 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: **

` ` |

** Output: **

[15, 60]

This book is not just about learning the code; even if you learn to program. If you want to program professionally, learning to code is not enough; For this reason, in addition to helping you program,...

05/09/2021

Big data is, admittedly, an overhyped buzzword used by software and hardware companies to boost their sales. Behind the hype, however, there is a real and extremely important technology trend with imp...

10/07/2020

Deep Learning for Coders with fastai and PyTorch: AI Applications Without a PhD. Deep learning is often seen as the exclusive domain of math PhDs and big tech companies. But as this how-to guide sh...

05/09/2021

Cracking the Coding Interview PDF: 189 Programming Questions and Solutions, 6th Edition. I am not a recruiter. I am a software engineer. And as such, I know what it's like to be asked to create ing...

31/08/2021

X
# Submit new EBook