人工智能深度学习入门练习之(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)
执行结果:
版权声明:本文为huanghanyu原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。