In [1]:
import tensorflow as tf

Notes:

  • tf.placehoder is used for input/label data, which usually don't change
  • tf.Variable is used as variables such as setting weights and biases
  • tf.constant defines constants matrix multiplication

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()


[5] [5]

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)


[[ 18.]]

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)


[[ 12.]]

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)


[[ 18.]]

In [24]:
# Hello world from TensorFlow

hello = tf.constant("Hello TensorFlow!!!")
sess = tf.Session()
print(sess.run(hello))
sess.close()


b'Hello TensorFlow!!!'