How to create variable in TensorFlow?

Ads
 

How to create variable in TensorFlow?

Hi,

How to create variable in TensorFlow?

Thanks

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









Related Tutorials/Questions & Answers:
How to create variable in TensorFlow?
Create Session Variable PHP
Advertisements
Create session variable.
JSP Create Variable
how to assign javascript variable value to a jsp variable
how to inherit static variable
create and use an array variable in a java program
How to define a constant variable in Java?
How to define variable in Velocity
How to create Animation
How to create Animation
how to value of one variable pass in other variable in revetse order
Php Sql Variable
How to pass javascript variable in Scriplet of JSP?
How do you pass a variable by value?
How to create an input box?
How to create arrays in JavaScript?
How to create a confirmation box?
how to create frame in swings
how to create notepad in java
how to create session for login
How to create a class in java
How to create form in Swings
how to create web aplli
how to create web aplli
how to create a queue - JMS
How to Assign struts2 property to jsp variable
How to Create Keyboard in JAVA
how to create ipa file
how to create a table
how to create uiwebview programmatically

Ads