In [1]:
print "hello, there"
In [2]:
a=2
c=a+2
print c
In [3]:
import numpy as np
In [4]:
import tensorflow as tf
In [5]:
a1=tf.ones([10])
sess = tf.Session()
print(sess.run(a1))
this is different from print a0 itself
In [6]:
print(a1)
In [7]:
hello = tf.constant('Hello, Joe!')
print(sess.run(hello))
print(hello)
Note that sess.run() gives us the actual output value, it takes tf variable The following tf.constant is required, otherwise it will generate error
In [8]:
a = tf.constant(10)
b = tf.constant(20)
c=a+b
print(sess.run(c))
Put everything in a session, no need to call session, just use .eval()
In [9]:
with tf.Session():
a = tf.constant(10)
b = tf.constant(20)
c=a+b
print c
print(c.eval())
the following code will generate error, that because c is not tf variable, thus cannot be run by sess.run
In [21]:
Out[21]:
In [10]:
a2=tf.ones([10,3])
print(sess.run(a2))
In [11]:
a3=tf.ones([10,3,2])
print(sess.run(a3))
b1 = tf.ones([4]) b2 = tf.constant([2.0, 2.0, 2.0, 2.0]) c = tf.add(b1, b2) print c
In [12]:
print(sess.run(c))
In [13]:
with tf.Session():
b1 = tf.ones([4])
b2 = tf.constant([2.0, 2.0, 2.0, 2.0])
c = tf.add(b1, b2)
print c.eval()
In [14]:
shape=[2,3]
x=tf.random_normal(shape, stddev=0.7)
with tf.Session():
print x.eval()
In [15]:
shape=[2,2]
x=tf.truncated_normal(shape, stddev=0.1)
with tf.Session():
print x.eval()
In [25]:
with tf.Session():
ones = tf.ones([2,2])
print ones.eval()
sigmoid = tf.sigmoid(ones, name="sigmoid")
print sigmoid.eval()
In [ ]: