Updating variable values in tensorflow
<p>I've have a basic question about updating the values of tensors via the tensorflow python api.</p>

<p>Consider the code snippet:</p>

<pre><code>x = tf.placeholder(shape=(None,10), ... )
y = tf.placeholder(shape=(None,), ... )
W = tf.Variable( randn(10,10), dtype=tf.float32 )
yhat = tf.matmul(x, W)
</code></pre>

<p>Now let's assume I want to implement some sort of algorithm that iteratively updates the value of W (e.g. some optimization algo). This will involve steps like:</p>

<pre><code>for i in range(max_its):
     resid = y_hat - y
     W = f(W , resid) # some update 
</code></pre>

<p>the problem here is that <code>W</code> on the LHS is a new tensor, not the <code>W</code> that is used in <code>yhat = tf.matmul(x, W)</code>!  That is, a new variable is created and the value of <code>W</code> used in my "model" doesn't update.</p>

<p>Now one way around this would be</p>

<pre><code> for i in range(max_its):
     resid = y_hat - y
     W = f(W , resid) # some update 
     yhat = tf.matmul( x, W)
</code></pre>

<p>which results in the creation of a new "model" for each iteration of my loop !</p>

<p>Is there a better way to implement this (in python) without creating a whole bunch of new models for each iteration of the loop - but instead updating the original tensor <code>W</code> "in-place" so to speak?</p>