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

时间:2020-06-16 15:33:56   收藏:0   阅读:33

代码实现:

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!