Srivatsa Srinath
Srivatsa Srinath

Reputation: 187

Query regarding the behavior of constant in tensorflow

I am a newbie to tensorflow and I have a question regarding the way the constant function operates. I have a simple program shown below:

import tensorflow as tf

a = tf.placeholder("float")
b = tf.constant(0.0)

y = tf.mul(x=a,y=b)

with tf.Session() as sess:
   print(sess.run(y,feed_dict={a:1,b:4}))

The output that I get is 4.0. However, I had set 'b' as a constant with value 0.

I was either looking for an error and a value of 0 as the output. Please help me understand this behavior.

Upvotes: 1

Views: 68

Answers (1)

nessuno
nessuno

Reputation: 27050

feed_dict is not only useful to pass value to placeholders, but it can be used to override the value of tensors in the graph.

When you run sess.run(y,feed_dict={a:1,b:4})) what happens is the filling of the placeholder a and the overriding of the constant value b.

Upvotes: 2

Related Questions