我已经开始学习张量流, 试图执行一个代码却不断得到错误的结果
import tensorflow as tf
# Immutable constants
a = tf.constant(6,name='constant_a')
b = tf.constant(3,name='contant_b')
c = tf.constant(10,name='contant_c')
d = tf.constant(5,name='contant_d')
mul = tf.multiply(a,b,name='mul')
div = tf.div(c,d,name="div")
# Output of the multiplication what needs to be added
addn = tf.add_n([mul,div],name="addn")
# Print out the result
print (addn)
结果是公正的
Tensor("addn:0", shape=(), dtype=int32)
奇怪的输出在执行了所有计算之后想要addn的值
问题是
打印数据只是给出
张量、形状及其数据类型
不给它任何时间点的价值。 这是因为上面的代码没有运行/执行。 它刚刚在tensorflow中构建了图形,但尚未执行以获得执行它的结果
session
是必需的您只需添加几行,创建一个会话,然后打印
输出 您将得到输出20
完整代码
相关问题 更多 >
编程相关推荐