TensorFlow入门
TensorFlow 入门
Check installation and versionPython 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSc v.1900 64bit(AMD64)onwin32Type"copyright","credits"or"license()"for more information.>>>import tensorflowastf>>> tf.version'1.3.0'>>>
Check installation and version Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import tensorflow as tf >>> tf._version_ '1.3.0' >>>
TensorFlow Hello World!#创建一个常量op(operation),op是默认图中节点,hello=tf.constant("Hello world!")#调用会话Session来启动默认图sess=tf.Session()#运行op并取得结果with tf.Session() as sess:print(sess.run(hello))print(sess.run(hello))#显示b'Hello world!#b表示Bytesliterals#关闭会话sess.close()
TensorFlow Hello World! #创建一个常量op(operation),op是默认图中节点, hello=tf.constant("Hello world!") #调用会话Session来启动默认图 sess=tf.Session() #运行op并取得结果 print(sess.run(hello)) #显示 b'Hello world! ‘ #b表示Bytes literals #关闭会话 sess.close() with tf.Session() as sess: print(sess.run(hello))
c=a+bnode1=tf.constant(3.0,tf.float32)node2=tf.constant(4.0)node3=tf.add(node1,node2)print("nodel:",ngdel,"node2:",node2,"node3:",ngde3)#node1:Tensor("Const_1:o",shape=(),dtype=float32node2:厂Tensor("Const 2:0",shape=(),dtype=float32)node3:Tensor("Add:0"shape=(),dtype=float32)#名称:操作名称+结果序号#维度:维度是可以改变的!获取维度信息为node1.get_shape(,改变维度为tf.reshape(node1,[2,1])#类型:不可变
node1=tf.constant(3.0,tf.float32) node2=tf.constant(4.0) node3=tf.add(node1,node2) print("node1:",node1, "node2:", node2, "node3:", node3) #node1: Tensor("Const_1:0", shape=(), dtype=float32) node2: Tensor("Const_2:0", shape=(), dtype=float32) node3: Tensor("Add:0", shape=(), dtype=float32) #名称:操作名称 + 结果序号 #维度:维度是可以改变的!获取维度信息为node1.get_shape(),改变维度为tf.reshape(node1, [2,1]) #类型:不可变 c=a+b
c=a+bsess=tf.Session()print("sess.run(node1,node2):",sess.run([node1,node2l))#sess.run(nodel,node2):[3.0,4.0]print("sess.run(node3):",sess.run(node3))#sess.run(node3):7.0
sess=tf.Session() print("sess.run(node1,node2):",sess.run([node1,node2])) #sess.run(node1,node2): [3.0, 4.0] print("sess.run(node3):",sess.run(node3)) #sess.run(node3): 7.0 c=a+b