import tensorflow as tf
x = tf.constant(3.0)
y = tf.constant(2.0)
r = tf.constant(.1)
while True:
with tf.GradientTape(persistent=False) as tape:
tape.watch([x, y])
y = 5 * x ** 2 - 3 * x + 10
dy = tape.gradient(y, x)
x -= dy * r
print(dy, x, y)
网友评论