Beginning ML – Variables : KnowDev

In previous post we have seen how tensorflow works. Now let’s understand one of the integral component i.e tensorflow variable. A tensorflow variables are used to represent the weights in neural network !

# create a tensorflow variable

var = tf.Variable(0)

cons = tf.constant(1)

We shall update the value of the variable var and there by understanding the working of tensorflow variable.

sum = tf.add(var, cons)

assign =tf.assign(var, sum)

The construction phase is completed. Let’s start the session.

with tf.Sesstion() as sess:

print ‘var:’,, ‘cons:’,

for _ in range(3):

print ‘updated var:’,

All variables are initialised in the graph by running

output :

var: 0 cons: 1




This is a small post and very specific. As tensorflow variables are very important I wanted to give a clear explanation of their working. Now, We can actually start building our own neural network ! We will using mnist dataset provided by The data is the format that is accepted by tensorflow. Therefore we need not to preprocess any data ! We shall train and test our first neural network in next !