Hi,
How to create variable in TensorFlow?
Thanks
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