What is TensorFlow?

What is TensorFlow?

TensorFlow is a python library(developed by Google) to build computational graph to solve mathematical probelms. We use symbolic mathematics to build the computational graph & execute them with tensorflow. Theano does exact same thing in their way. TensorFlow provides us an API to do these.

You might think of TensorFlow Core programs as consisting of two discrete sections:

1. Building the computational graph.
2. Running the computational graph.

A computational graph is a series of TensorFlow operations arranged into a graph of nodes. Let’s build a simple computational graph. Each node takes zero or more tensors as inputs and produces a tensor as an output. One type of node is a constant. Like all TensorFlow constants, it takes no inputs, and it outputs a value it stores internally. We can create two floating point Tensors node1 and node2 as follows[1]:

import tensorflow as tf

node1 = tf.constant(3.0, tf.float32)
node2 = tf.constant(4.0) # also tf.float32 implicitly
print(node1, node2)
(<tf.Tensor 'Const:0' shape=() dtype=float32>, <tf.Tensor 'Const_1:0' shape=() dtype=float32>)

Wow! The output is a graph too! To run/execute the graph we need to init a Session object & invoke run method.

sess = tf.Session()
print(sess.run([node1, node2]))
[3.0, 4.0]

Now solve this:

Declare 2 constant using tensorflow and add them.

’’’ constant a

constant b

return a+b ‘’’

a = tf.constant(5.0)
b = tf.constant(3.0)

y = a+b

print(sess.run(y))
8.0


References & Read more:

1: Deep Learning Book tutorial

1: Datacamp Numpy tutorial

2: Scipy Numpy tutorial

3: Tensorflow official Getting Started