tf.constant函数说明tf.constant(value,dtype=None,shape=None,name='Const")创建一个常量tensor,按照给出value来赋值,可以用shape来指定其形状。value可以是一个数,也可以是一个1ist。如果是一个数,那么这个常亮中所有值的按该数来赋值。如果是list,那么len(value)一定要小于等于shape展开后的长度。赋值时,先将value中的值逐个存入。不够的部分,则全部存入value的最后一个值。a=tf.constant(2,shape=[2])#[22]b =tf.constant(2,shape=[2,2])#[[2 2]# [2 2]]c=tf.constant([1,2,3],shape=[6])#[1233331d = tf.constant([1,2,3],shape=[3,2])#[[12]#[33]#[33]]
tf.constant(value,dtype=None,shape=None,name=’Const’) 创建一个常量tensor,按照给出value来赋值,可以用shape来指定其形状。value可以是 一个数,也可以是一个list。 如果是一个数,那么这个常亮中所有值的按该数来赋 值。 如果是list,那么len(value)一定要小于等于shape展开后的长度。赋值时,先将 value中的值逐个存入。不够的部分,则全部存入value的最后一个值。 a = tf.constant(2,shape=[2]) #[2 2] b = tf.constant(2,shape=[2,2]) #[[2 2] # [2 2]] c = tf.constant([1,2,3],shape=[6]) #[1 2 3 3 3 3] d = tf.constant([1,2,3],shape=[3,2]) #[[1 2] # [3 3] # [3 3]] tf.constant函数说明
tf.InteractiveSession()#进入一个交互式TensorFlow会话importtensorflow as tfsess=tf.InteractiveSession()X = tf.Variable([1.0,2.0l)a=tf.constant([3.0,3.0])#使用初始化器initializerop的run()方法初始化‘xx.initializer.run()# x+as=tf.add(x,a)print(s.eval())#s.eval()相当于sess.run(s)#==>[4. 5.]#tf.InteractiveSession()是一种交互式的session方式,它让自己成为了默认的session,也就是说用户在不需要指明用哪个session运行的情况下,就可以运行起来
# 进入一个交互式 TensorFlow 会话. import tensorflow as tf sess = tf.InteractiveSession() x = tf.Variable([1.0, 2.0]) a = tf.constant([3.0, 3.0]) # 使用初始化器 initializer op 的 run() 方法初始化 'x' x.initializer.run() # x+a s = tf.add(x, a) print (s.eval()) # s.eval()相当于sess.run(s) # ==> [4. 5.] tf.InteractiveSession() # tf.InteractiveSession()是一种交互式的session方式,它让自己成为了默认的session,也就是说用户 在不需要指明用哪个session运行的情况下,就可以运行起来
What is a Data Flow Graph?·Nodes in the graph representmathematicaloperationsEdgesrepresentthemultidimensional data arrays(tensors)communicatedbetween them
What is a Data Flow Graph? ● Nodes in the graph represent mathematical operations ● Edges represent the multidimensional data arrays (tensors) communicated between them
Placeholdera=tf.placeholder(tf.float32)b=tf.placeholder(tf.float32)adder node=a+bSess=tf.Session()print(sess.run(adder node,feeddict=(a:3,b:4.5)))#7.5print(sess.run(adder_node,feed_dict=(a:[1,3],b:[2,4]}))#[3. 7.]tf.placeholder(dtype,shape=None,name=None)形参,用于定义过程,在执行的时候再赋具体值·dtype:数据类型·Shape:数据形状·Name:名称
a=tf.placeholder(tf.float32) b=tf.placeholder(tf.float32) adder_node=a+b sess=tf.Session() print(sess.run(adder_node,feed_dict={a:3,b:4.5})) #7.5 print(sess.run(adder_node,feed_dict={a:[1,3],b:[2,4]})) # [3. 7.] Placeholder tf.placeholder(dtype,shape=None,name=None) 形参,用于定义过程,在执行的时候再赋具体值 • dtype:数据类型 • Shape:数据形状 • Name:名称