user6857504
user6857504

Reputation: 569

TensorFlow unexpected addition result

I am running the following code:

import tensorflow as tf

sess = tf.InteractiveSession()
x = tf.placeholder(tf.float32)
y = tf.Variable(5.0)

init = tf.initialize_all_variables() sess.run(init)

The following gives different results:

y = x + y  
for i in xrange(10):
    print sess.run(y, {x: 1.0})

Gives: 6, 6, 6, 6, ...

Compare with:

for i in xrange(10):
    y = x + y    
    print sess.run(y, {x: 1.0})

Prints: 6,7,8,9 ...

Why is the result different? I thought that:

sess.run(y, {x: 1.0})

Does: y = x + 1

Upvotes: 1

Views: 81

Answers (1)

Dmytro Danevskyi
Dmytro Danevskyi

Reputation: 3159

Every time y = x + y is executed, computational graph changes, i.e. in first iteration you add y = x + y to your graph, and so on.

Upvotes: 3

Related Questions