` 6 # a rank 0 tensor; it has shape [] (a scalar)`

[4. ,5., 6.] # a rank 1 tensor; It has shape [3] (a vector)

[[3., 4., 5.], [10., 20., 30.]] # a rank 2 tensor; it has shape [2, 3] (a matrix)

[[[66., 77., 88.]], [[11., 12., 13.]]] # a rank 3 tensor,it has shape [2, 1, 3]

`import tensorflow as tf`

The way the tensorflow works is that first, we need to build a computational graph or a model .The model could be as few a single node or as many as possible. Then after the model is ready then we create a tensorflow session and start the session with the input nodes. When session's run method is called then only all the computation will happen.

To declare a node with a constant value in tensorflow we use tf.constant(value,datatype) .The first parameter of tf.constant() function is the value you what to put in the node and 2nd parameter is used to define the data type of the constant. TensorFlow can implicitly also identify the type of constant so if we leave out the second parameter then it would also be fine. for example

` `

firstNode=tf.constant(7.0, dtype=tf.float32)

secondNode=tf.constant(14.0)

print(firstNode,secondNode)

Output will be a tensor

` Tensor("Const:0", shape=(), dtype=float32) Tensor("Const_1:0", shape=(), dtype=float32) `

Remember we can get the value 7.0 and 14.0 only when we run the nodes. Also, remember that output of the node will also be a tensor object.

To run them we need to create a tensorflow session as:

sess=tf.Session()

print(sess.run([firstNode , secondNode]))

This will run those nodes and will give output as

[7.0, 14.0]

We can even perform operation on these two nodes as

thirdNode=tf.add(node1, node2)

print("Sum value is : ",sess.run(thirdNode))

this will display (7.0+14.0) value as

` 21.0 `

Notice if just print thirdNode then output will be a tensor with no computed answer on it.

We can even store array or list of values as:

` `

x=tf.constant([3,4,5])

y=tf.constant(8)

addOp=x+y

with tf.Session() as sess:

print(sess.run(addOp))

Output :`[ 11 12 13]`

Here, we have added 8 to [3,4,5] to all elements of array.

We can also perform array addition of two variables in tensorflow as:

x=tf.constant([3,4,5])

y=tf.constant([4,5,6])

addOp=x+y

with tf.Session() as sess:

print(sess.run(addOp))

Output :`[ 7 9 11]`

x=tf.placeholder(tf.float32)

y=tf.placeholder(tf.float32)

z=x+y

Placeholders allows us to put multiple inputs

` print(sess.run(z,{x: 10.0, y:20.0})) `

the output will be

` 30.0 `

Here we specified 10.0 value to node x and 20.0 value to node y. Then we called the sess.run method on z to perform the addition operation on x and y nodes.

`tf.global_variables_initializer()`

does the job of initializing all the variables. Example as follows:

W=tf.Variable(3.5, dtype=tf.float32,name="W")

b=tf.Variable(4.6, dtype=tf.float32,name="b")

addVar=W+b;

with tf.Session() as sess:

init=tf.global_variables_initializer()

sess.run(init)

print(sess.run(addVar))

Output :`8.1`

- Introduction to Neural Networks
- Datatypes and Arithmetic Operators in tensorflow