Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
5 views
in AI and Deep Learning by (10.2k points)
edited by

I want to assign a value to a TensorFlow variable in Python and I am using this:

import tensorflow as tf

import numpy as np

x = tf.Variable(0)
init = tf.initialize_all_variables()
sess = tf.InteractiveSession()
sess.run(init)

print(q.eval())

q.assign(1) 

print(q.eval()):

And this is the output:

 0

0

 The value isn't changing, what should I do to correct this?

1 Answer

0 votes
by (46k points)
edited by

Just use operation.run() or session.run() to call the operation:

assign_op = y.assign(0)
sess.run(assign_op)  # or `assign_op.op.run()`
print(y.eval())
# ==> 0

Interested in learning Tableau? Check out this AI Tutorial!

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.2k users

Browse Categories

...