Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x = tf.ones((2, 2))
- with tf.GradientTape() as t:
- t.watch(x)
- y = tf.reduce_sum(x)
- z = tf.multiply(y, y)
- # Derivative of z with respect to the original input tensor x
- dz_dx = t.gradient(z, x)
- for i in [0, 1]:
- for j in [0, 1]:
- assert dz_dx[i][j].numpy() == 8.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement