Variable Variable
Variable is also based on the op, it is a special tensor can be stored persistence, his value is the tensor.
Creating variables
Create a new variable with a value init_value tf.Variable (init_value = None, name = None)
Parameter Description:
- assign (value): assign a new value to a variable value new session
- And returns the value calculating variables: evaluate (session = None)
- name: the property represents a variable name
Variable initialization
Variables must be initialized, such as
. 1 Import tensorflow AS TF 2 . 3 . 4 A = tf.constant ([ . 1 , 2 , . 3 , . 4 , . 5 ]) . 5 # Create a normally distributed random variable . 6 var = tf.Variable (tf.random_normal ([ 2 , . 3 ] , Mean = 0.0 , STDDEV = 1.0 )) . 7 . 8 # as the display initialization OP . 9 init_op = tf.global_variables_initializer () 10 . 11 with tf.Session () AS Sess: 12 is # variables must be initialized variable OP 13 is sess.run (init_op) 14 print (sess.run ([a, var ]))
We will have to be called before the session init_op = tf.global_variable_initializer () to do the initial display of variables, the variables
Become a op, and then call the session sess.run (init_op) to initialize variables.