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:

sess.run(tf.initialize_all_variables())

print ‘var:’, sess.run(var), ‘cons:’, sess.run(cons)

for _ in range(3):

sess.run(assign)

print ‘updated var:’, sess.run(var)

All variables are initialised in the graph by running sess.run(tf.initialise_all_varialbles).

output :

**var: 0 cons: 1**

**1**

**2**

**3**

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 **tensorflow.org. **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 !

### Like this:

Like Loading...

*Related*