How to create variable in TensorFlow?

 
 

Share on Google+Share on Google+

Java Coder
How to create variable in TensorFlow?
1 Answer(s)      a month and 23 days ago
Posted in : TensorFlow

Hi,

How to create variable in TensorFlow?

Thanks

Ads
View Answers

October 2, 2017 at 1:01 PM


Hi,

In TensorFlow you can't use python variable, you have to create the TensorFlow variable to use it with TensorFlow graph.

Then tf.variable() method is used to create variable in TensorFlow.

The TensorFlow variable exists outside the single run call.

Here is an example of variable in TensorFlow:

import tensorflow as tf
a = tf.Variable(4,)
sess = tf.Session()
model = tf.global_variables_initializer()
sess.run(model)
print(sess.run(a))

Here we are declaring a variable with initial value 4. And when program runs we are just printing its data.

Here is output:

>>> import tensorflow as tf
>>>
>>> a = tf.Variable(4,)
>>>
>>> sess = tf.Session()
>>> model = tf.global_variables_initializer()
>>>
>>> sess.run(model)
>>>
>>> print(sess.run(a))
4
>>>

You can learn TensorFlow at following urls:

Learn TensorFlow with above tutorials.

Thanks


Ads









Ads

 
Advertisement null

Ads