人工智能深度学习入门练习之(3)求导

代码实现:

import tensorflow as tf
# 创建4个张量
a=tf.constant(1.)
b=tf.constant(2.)
c=tf.constant(3.)
w=tf.constant(4.)
with tf.GradientTape() as tape:
    tape.watch([w])
    y = a * w ** 2 + b * w + c
[dy_dw] = tape.gradient(y,[w])
print(dy_dw)

执行结果:

原文地址:https://www.cnblogs.com/huanghanyu/p/13141121.html