我想在几个会话迭代(添加)中更新变量buff,以便我可以在下一个会话(乘法)中处理buff列表。但是,buff变量在每次迭代时都会初始化。步骤2的输出为[5]
,而不是预期的[4,5]
。我该如何解决这个问题?
a = tf.placeholder(tf.int16)
b = tf.placeholder(tf.int16)
buff = []
# Define some operations
add = tf.add(a, b)
buff.append(add)
# Define a multiplication
two = tf.constant(2, tf.int16)
mul = tf.multiply(two, buff)
with tf.Session() as sess:
# Step1: Run first Addition
value_add = sess.run(buff, feed_dict={a: 1, b:3})
# Step2: Update buff1
value_add = sess.run(buff, feed_dict={a: 2, b:3})
print("Addition with variables a and b: ", value_add)
# Step3: Multiply buff1
value_mul = sess.run(mul)
print("Multiplication of buff2: ", value_mul)enter code here
此外,我想应用步骤3。但是,此步骤失败了,因为tensorflow需要feed_dict参数。当我设置feed_dict={buff = buff_value}
时,它抱怨feed_dict
操作不支持列表。我该如何解决这个问题?