0

I am trying to calculate partial derivative for the below function, could you advise if this is the right way to calculate partial derivative using TensorFlow?

f(x,y,z) = xy+z pow 2 + 1/x

x = tf.Variable(2, name='x')
y = tf.Variable(1, name='y')
z = tf.constant(4, name='z')

with tf.GradientTape(persistent=True) as t:
  t.watch(x)
  f = x*y + tf.pow(z,2) + tf.divide(1,x)

g = tape.gradient(f, [x,y,z])

print(g)
bigskull
  • 739
  • 2
  • 13
  • 23
  • 1
    It looks good. The minor issues are: `g = t.gradient(f, [x, y, z])` and variables `x`, `y`, `z` should be double. – user1635327 Sep 16 '21 at 10:18
  • Also, the topic of your question and the content seems to be a bit different. Are you interested in a Hessian matrix or the gradient? – user1635327 Sep 16 '21 at 10:20

0 Answers0