title: Reuse variables in tensorflow
body: <p>I can't understand how variables and scopes are supposed to be used. Here there is my failed attempt to <strong>re</strong>use a variable defined inside a function:</p>
  
  <pre><code>def basedOnVariableFunctAffectingVar(a):
      v = tf.get_variable("nameV2",
                          dtype=tf.float64,
                          initializer=tf.constant([0.0,1],
                                                  dtype=tf.float64))
      aa = tf.constant(np.array([a,a]))
      t = v + aa
      v.assign(t)
      return t
  </code></pre>
  
  <p>And then I call the function:</p>
  
  <pre><code>with tf.variable_scope("Scope0"):
      res1 = basedOnVariableFunctAffectingVar(2.0)
  
  with tf.Session() as session:
      session.run(tf.global_variables_initializer())
      result1 = session.run(res1)
  
      with tf.variable_scope("Scope0",
                             reuse=True):
          a = tf.get_variable("nameV2", dtype=tf.float64)
      print(session.run(a))
      print(result1)
  </code></pre>
  
  <p>Quite surprisingly the output is: </p>
  
  <blockquote>
    <p>[0. 1.] [2. 3.]</p>
  </blockquote>
  
  <p>I expected </p>
  
  <blockquote>
    <p>[2. 3.] [2. 3.]</p>
  </blockquote>
  
  <p>Thanks to anyone clarifying the concepts of variable and scopes in TF.</p>