瀏覽代碼

adde basic examples

Aymeric Damien 9 年之前
父節點
當前提交
c1d6157e3f
共有 2 個文件被更改,包括 31 次插入0 次删除
  1. 22 0
      basic_operations.py
  2. 9 0
      helloworld.py

+ 22 - 0
basic_operations.py

@@ -0,0 +1,22 @@
+import tensorflow as tf
+
+#With constants
+a = tf.constant(2)
+b = tf.constant(3)
+
+with tf.Session() as sess:
+    print "a=2, b=3"
+    print "Addition with constants: %i" % sess.run(a+b)
+    print "Multiplication with constants: %i" % sess.run(a*b)
+
+
+#With variables
+a = tf.placeholder(tf.types.int16)
+b = tf.placeholder(tf.types.int16)
+
+add = tf.add(a, b)
+mul = tf.mul(a, b)
+
+with tf.Session() as sess:
+    print "Addition with variables: %i" % sess.run(add, feed_dict={a: 2, b: 3})
+    print "Multiplication with variables: %i" % sess.run(mul, feed_dict={a: 2, b: 3})

+ 9 - 0
helloworld.py

@@ -0,0 +1,9 @@
+import tensorflow as tf
+
+#Simple hello world using TensorFlow
+
+hello = tf.constant('Hello, TensorFlow!')
+
+sess = tf.Session()
+
+print sess.run(hello)