import tensorflow as tf
w1 = tf.Variable([[1, 2]])
w2 = tf.Variable([[3, 4]])
y = tf.matmul(w1, [[9], [10]])
grads = tf.gradients(y, [w1])
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
gradval = sess.run(grads)
print(gradval)
tensorflow gradients好像不支持 int型的Tensor 的gradients 把w1的设置成float类型的例如tf.float32 gards就能算了