In [1]:
import tensorflow as tf
Notes:
In [3]:
a = tf.constant([2])
b = tf.constant([3])
# a = tf.constant(2)
# b = tf.constant(3)
c = a + b
d = tf.add(a,b)
# METHOD ONE TO INITIALISE SESSION
session = tf.Session()
result = session.run(c)
result1 = session.run(d)
print(result,end = " ")
print(result1)
session.close()
In [15]:
matrix1 = tf.placeholder("float",shape = (1,2),name = "matrix1")
matrix2 = tf.placeholder("float",shape = (2,1), name = "matrix2")
product = tf.matmul(matrix1,matrix2)
# METHOD TWO OF INITIALISING SESSION
with tf.Session() as session:
result = session.run(product,feed_dict = {matrix1:[[3,3]],matrix2:[[3],[3]]})
print(result)
In [22]:
matrix1 = tf.placeholder(tf.float32,shape = (1,2))
matrix2 = tf.placeholder("float",None)
product = tf.matmul(matrix1,matrix2)
with tf.Session() as session:
result = session.run(product,feed_dict = {matrix2:[[3],[3]],matrix1:[[2,2]]})
print(result)
In [28]:
a = tf.constant([[3.,3.]])
b = tf.constant([[3.],[3.]])
product = tf.matmul(a,b)
with tf.Session() as session:
with tf.device("/gpu:0"): # using the GPU
result = session.run(product)
print(result)
In [24]:
# Hello world from TensorFlow
hello = tf.constant("Hello TensorFlow!!!")
sess = tf.Session()
print(sess.run(hello))
sess.close()