Skip to content

Instantly share code, notes, and snippets.

@hadifar
Last active January 5, 2019 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hadifar/34f0a3eaab14827da3452a28cc662eb9 to your computer and use it in GitHub Desktop.
Save hadifar/34f0a3eaab14827da3452a28cc662eb9 to your computer and use it in GitHub Desktop.
import tensorflow as tf
tf.enable_eager_execution()
x = tf.get_variable(initializer=3.0, name='x')
with tf.GradientTape() as tape:
y = tf.square(x)
y_grad = tape.gradient(y, x)
print(x.numpy())
print(y.numpy())
print(y_grad.numpy())
############ output ###############
>>> 3.0
>>> 9.0
>>> 6.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment