代码实现:

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

执行结果:

 

版权声明:本文为huanghanyu原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/huanghanyu/p/13141121.html