How to overwrite a tensorflow variable after it has been initialized?
<p>Assuming codes like this:</p>

<pre><code>    sess.run(tf.initialize_all_variables())

    assign_op_0 = embedding_list[0].assign(tf.random_normal([35019, 32], stddev = 0.0))
    assign_op_1 = embedding_list[1].assign(tf.random_normal([35019, 32], stddev = 0.0))

    sess.run(assign_op_0)
    sess.run(assign_op_1)
</code></pre>

<p>embedding_list[0] and embedding_list[1] are two variables which have been initialized in the first line of codes. Now I want to overwrite with some new values, so I have the following four lines of code, however, I don't know if this is correct. And I can not even print the values of the embedding_list[0] and embedding_list[1]. When I do like this:</p>

<pre><code>print(embedding_list[0].eval(session=sess.run))
</code></pre>

<p>it has this error:</p>

<pre><code>Traceback (most recent call last):
  File "/home/zhao/DeepQA-master/main.py", line 29, in &lt;module&gt;
    chatbot.main()
  File "/home/zhao/DeepQA-master/chatbot/chatbot.py", line 213, in main
    print(embedding_list[0].eval(session=self.sess.run))
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/variables.py", line 437, in eval
    return self._variable.eval(session=session)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 555, in eval
    return _eval_using_default_session(self, feed_dict, self.graph, session)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 3494, in _eval_using_default_session
    if session.graph is not graph:
AttributeError: 'function' object has no attribute 'graph'
</code></pre>

<p>Try as follows:</p>

<pre><code>sess.run(tf.initialize_all_variables())
W_0 = tf.Variable(tf.random_normal([35019, 32], stddev = 0.0))
assign_op_0  = W_0.assign(embedding_list[0])
sess.run(assign_op_0)
</code></pre>

python tensorflow