title: sum over a list of tensors in tensorflow
body: <p>I have a deep neural network where the weights between layers are stored in a list. </p>
  
  <p><code>layers[j].weights</code> I want to incluse the ridge penalty in my cost function. I need then to use something like 
  <code>tf.nn.l2_loss(layers[j].weights**2 for j in range(self.n_layers))</code> i.e. the squared sum of all the weights. </p>
  
  <p>In particular the weights are defined as:</p>
  
  <pre><code>&gt;&gt;&gt; avs.layers
  [&lt;neural_network.Layer object at 0x10a4b2a90&gt;, &lt;neural_network.Layer object at 0x10ac85080&gt;, &lt;neural_network.Layer object at 0x10b0f3278&gt;, &lt;neural_network.Layer object at 0x10b0eacf8&gt;, &lt;neural_network.Layer object at 0x10b145588&gt;, &lt;neural_network.Layer object at 0x10b165048&gt;, &lt;neural_network.Layer object at 0x10b155ba8&gt;]
  &gt;&gt;&gt;
  &gt;&gt;&gt; avs.layers[0].weights
  &lt;tensorflow.python.ops.variables.Variable object at 0x10b026748&gt;
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>How can I do that in tensorflow ?</p>