TensorFlow has functions to solve other more complex tasks. For example, we will use a mathematical operator that calculates the derivative of `y`

with respect to its expression `x`

parameter. For this purpose, we use the `tf.gradients()`

function.

Let us consider the math function `y = 2`

. We want to compute the gradient *x*²`di y`

with respect to `x=1`

. The following is the code to compute this gradient:

- First, import the TensorFlow library:
**import TensorFlow as tf** - The
`x`

variable is the independent variable of the function:**x = tf.placeholder(tf.float32)** - Let's build the function:
**y = 2*x*x** - Finally, we call the
`tf.gradients()`

function with`y`

and`x`

as arguments:**var_grad = tf.gradients(y, x)** - To evaluate the gradient, we must build a session: ...

Start Free Trial

No credit card required