In [6]:
import tensorflow as tf
import numpy as np

In [30]:
sess = tf.Session()
x = tf.placeholder("float", [None, 100])
def rando_func(sess):
    result = tf.reduce_sum(x) ** 2
    return result
y = rando_func(sess)
sess.run(tf.initialize_all_variables())
val = sess.run(rando_func(sess), feed_dict = {x:np.random.randn(200, 100)})
print(sess.run(tf.gradients(rando_func(sess), [x]), feed_dict = {x:np.random.randn(200, 100)}))
print(sess.run(tf.gradients(y, [x]), feed_dict = {x:np.random.randn(200, 100)}))


[array([[-156.41358948, -156.41358948, -156.41358948, ..., -156.41358948,
        -156.41358948, -156.41358948],
       [-156.41358948, -156.41358948, -156.41358948, ..., -156.41358948,
        -156.41358948, -156.41358948],
       [-156.41358948, -156.41358948, -156.41358948, ..., -156.41358948,
        -156.41358948, -156.41358948],
       ..., 
       [-156.41358948, -156.41358948, -156.41358948, ..., -156.41358948,
        -156.41358948, -156.41358948],
       [-156.41358948, -156.41358948, -156.41358948, ..., -156.41358948,
        -156.41358948, -156.41358948],
       [-156.41358948, -156.41358948, -156.41358948, ..., -156.41358948,
        -156.41358948, -156.41358948]], dtype=float32)]
[array([[ 163.07661438,  163.07661438,  163.07661438, ...,  163.07661438,
         163.07661438,  163.07661438],
       [ 163.07661438,  163.07661438,  163.07661438, ...,  163.07661438,
         163.07661438,  163.07661438],
       [ 163.07661438,  163.07661438,  163.07661438, ...,  163.07661438,
         163.07661438,  163.07661438],
       ..., 
       [ 163.07661438,  163.07661438,  163.07661438, ...,  163.07661438,
         163.07661438,  163.07661438],
       [ 163.07661438,  163.07661438,  163.07661438, ...,  163.07661438,
         163.07661438,  163.07661438],
       [ 163.07661438,  163.07661438,  163.07661438, ...,  163.07661438,
         163.07661438,  163.07661438]], dtype=float32)]

In [ ]:
tf.gradients(rando_func())