Skip to content

Instantly share code, notes, and snippets.

@ispamm
Last active March 7, 2018 11:37
Show Gist options
  • Save ispamm/8ec1ce93afbb30ff65f135fcae325391 to your computer and use it in GitHub Desktop.
Save ispamm/8ec1ce93afbb30ff65f135fcae325391 to your computer and use it in GitHub Desktop.
def square_f(W):
# Return a tensor with elements squared
return tf.square(W)
f_grad = tfe.gradients_function(square_f, params=['W'])
print(f_grad(tf.constant(0.3)))
# Prints [<tf.Tensor: id=xx, shape=(), dtype=float32, numpy=0.6>]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment