In [12]:
import tensorflow as tf
In [13]:
# Create TensorFlow object called tensor
hello_constant = tf.constant('Hello World!')
In [14]:
with tf.Session() as sess:
# Run the tf.constant operation in the session
output = sess.run(hello_constant)
print(output)
In [15]:
# A is a 0-dimensional int32 tensor
A = tf.constant(1234)
In [16]:
with tf.Session() as sess:
# Run the tf.constant operation in the session
output = sess.run(A)
print(output)
In [17]:
# B is a 1 dimentional int32 tensor
B = tf.constant([123,456,789])
In [18]:
with tf.Session() as sess:
# Run the tf.constant operation in the session
output = sess.run(B)
print(output)
In [19]:
# C is a 2-dimensional int32 tensor
C = tf.constant([[123,456,789],[222,333,444]])
In [20]:
with tf.Session() as sess:
# Run the tf.constant operation in the session
output = sess.run(C)
print(output)
In [21]:
with tf.Session() as sess:
print(sess.run(hello_constant))
print(sess.run(A))
print(sess.run(B))
print(sess.run(C))
In [27]:
x = tf.placeholder(tf.string)
with tf.Session() as sess:
output = sess.run(x, feed_dict={x: 'Hello World'})
print(output)
In [40]:
x = tf.placeholder(tf.string)
y = tf.placeholder(tf.int32)
z = tf.placeholder(tf.float32)
with tf.Session() as sess:
output = sess.run(z, feed_dict={x: 'Test String', y: 123, z: 45.67})
print(output)
print(x)
print(y)
print(z)
In [53]:
def run():
output = None
x = tf.placeholder(tf.int32)
with tf.Session() as sess:
output = sess.run(x, feed_dict={x: 123})
print(output)
return output
In [54]:
output = None
x1 = tf.placeholder(tf.int32)
with tf.Session() as sess:
output = sess.run(x1, feed_dict={x1: 123})
print(output)