Up: Automatic differentiation with GradientTape [Top][Contents]
GradientTape
import tensorflow as tf x = tf.constant(10.0) with tf.GradientTape() as tape: tape.watch(x) y = x ** 2 dx = tape.gradient(y, x) f"y = {y}, dy/dx = {dx}"
y = 100.0, dy/dx = 20.0