0
こんにちは、私はテンソルをマップしようとしているPython関数を持っています。私は本質的にすべての要素を関数を通して実行する必要があります。私はどのようにこの関数に2つのパラメータをマップするか分からない。これだけでなく、私はそれは私にエラーを与えて二番目のパラメータ削除した場合でも:ここTensorflow - 2つのパラメータを使ってPython関数をマッピングする
TypeError: bad operand type for unary -: 'list'
を私の完全なコードは次のとおりです。
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()
私はこの次ました:https://www.tensorflow.org/api_docs/python/tf/py_func
EDITを 私はtensorflowsライブラリを使ってexp関数を実行できます:
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))
これは動作しますが、私はそれをどのように取得することができますデリバティブを使用する?どのように関数に2つのパラメータを渡すことができますか? – Kevin
result = sigmoid(a、derivative = True)を呼び出すだけですか? –
ありがとう、私はnumpyを必要とする操作を行う必要がありましたか?私が理解していることから、私はこれをすることができませんでしたか? – Kevin