import numpy as np
import tensorflow as tf
#a placeholder is like a variable that you can
#set later
a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
#build the sum operation
c = a+b
#get the tensorflow session
sess = tf.Session()
#initialize all variables
sess.run(tf.initialize_all_variables())
#Now you want to sum 2 numbers
#first set up a dictionary
#that includes the numbers
#The key of the dictionary
#matches the placeholders
# required for the sum operation
feed_dict = {a:2.0, b:3.0}
#now run the sum operation
ppx = sess.run([c], feed_dict)
#print the result
print(ppx)
下面是一个小片段,让您开始:
首先,让我们从定义张量开始
现在,我们有一个简单的图,它可以添加两个常数。我们现在只需要创建一个会话来运行我们的图表:
相关问题 更多 >
编程相关推荐