Hi I have a python function where I am trying to map a tensor to. I essentially need to run every element through the function. I am not sure how to map the two parameters to this function. Not only this but even when I remove the second parameter it gives me an error:
TypeError: bad operand type for unary -: 'list'
Here is my full code:
import tensorflow as tf
def sigmoid(x, derivative = False):
if derivative == True:
return (1.0/(1+math.exp(-x))) * (1.0 - (1.0/(1+math.exp(-x))))
return 1.0/(1+math.exp(-x))
# build computational graph
a = tf.placeholder('float', None)
result = tf.map_fn(sigmoid, [a] , tf.float32)
# initialize variables
init = tf.global_variables_initializer()
# create session and run the graph
with tf.Session() as sess:
sess.run(init)
print sess.run(result, feed_dict={a: [2,3,4]})
# close session
sess.close()
I was following this: https://www.tensorflow.org/api_docs/python/tf/py_func
EDIT I can do the exp function using tensorflows library:
def sigmoid(x, derivative = False):
if derivative == True:
return (1.0/(1+tf.exp(-x))) * (1.0 - (1.0/(1+tf.exp(-x))))
return 1.0/(1+tf.exp(-x))