How to create variable in TensorFlow?

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









Related Tutorials/Questions & Answers:
How to create variable in TensorFlow?
Create Session Variable PHP
Advertisements
JSP Create Variable
Create session variable.
how to assign javascript variable value to a jsp variable
create and use an array variable in a java program
how to inherit static variable
how to value of one variable pass in other variable in revetse order
How to create Animation
How to create Animation
How to define a constant variable in Java?
how to define variable in node js
how to define variable in node js
Php Sql Variable
How to define variable in Velocity
How to pass javascript variable in Scriplet of JSP?
How do you pass a variable by value?
How to Assign struts2 property to jsp variable
how to pass class variable to another class
How I can cast a variable in Scala?
How I can cast a variable in Scala?
How to set a variable value using velocity
how to call jsp variable through servlet
how to set the class path variable in tomcat ?
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
Static variable 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 Create Keyboard in JAVA
how to create ipa file
how to create rdd in pyspark
how to create a table
how to create uiwebview programmatically
How To Create a Table.
How to create charts in Java?
how to create array in r
How to create options in HTML
how to create array in python
how to create vector in r
how to create interfaces in java
how to create servlet
how to create dao

Ads