4
import tensorflow as tf
array = tf.Variable(tf.random_normal([10]))
i = tf.constant(0)
l = []
def cond(i,l):
return i < 10
def body(i,l):
temp = tf.gather(array,i)
l.append(temp)
return i+1,l
index,list_vals = tf.while_loop(cond, body, [i,l])
上記のコードと同様の方法でテンソル配列を処理します。 whileループの本体では、要素ごとに配列を処理して、ある機能を適用したいと思っています。デモンストレーションのために、私は小さなコードスニペットを与えました。ただし、次のようなエラーメッセージが表示されます。ループ実行中のテンソルフロー
ValueError: Number of inputs and outputs of body must match loop_vars: 1, 2
これを解決するための助けに感謝します。
おかげドキュメント引用