这是我的第一个张量流代码。
如果我分开添加它可以工作,但我相信有一种方法可以在一行中添加N个张量。
import tensorflow as tf
# Create a graph.
g = tf.Graph()
# Establish the graph as the "default" graph.
with g.as_default():
# Assemble a graph consisting of the following three operations:
# * Two tf.constant operations to create the operands.
# * One tf.add operation to add the two operands.
x = tf.constant(8, name="x_const")
y = tf.constant(5, name="y_const")
z = tf.constant(4, name="z_const")
my_sum = tf.add_n(x, y, z, name="z_y_x_sum")
# Now create a session.
# The session will run the default graph.
with tf.Session() as sess:
print my_sum.eval()
你可以帮我弄清楚是什么问题吗?
答案 0 :(得分:0)
您需要将张量放入列表中:
my_sum = tf.add_n([x, y, z], name="z_y_x_sum")