Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. x = tf.ones((2, 2))
  2.  
  3. with tf.GradientTape() as t:
  4. t.watch(x)
  5. y = tf.reduce_sum(x)
  6. z = tf.multiply(y, y)
  7.  
  8. # Derivative of z with respect to the original input tensor x
  9. dz_dx = t.gradient(z, x)
  10. for i in [0, 1]:
  11. for j in [0, 1]:
  12. assert dz_dx[i][j].numpy() == 8.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement