title: How to initialize weights for simple deep Neural Network in tensorflow using for loop and xavier?
body: <p>I am trying to initialize weights of multi-layer Neural Network using the following code in tensorflow.</p>
  
  <pre class="lang-py prettyprint-override"><code>def initialize_parameters(layers_dims):
      parameters = {}
      tf.set_random_seed(1)                  
  
      L = len(layers_dims)
  
      for l in range(1, L):
          parameters['W' + str(l)] = tf.get_variable("parameters['W' + str(l)]", [layers_dims[l],layers_dims[l-1]], initializer = tf.contrib.layers.xavier_initializer(seed = 1))
          parameters['b' + str(l)] = tf.get_variable("parameters['b' + str(l)]", [layers_dims[l],1], initializer = tf.zeros_initializer())
      return parameters
  </code></pre>
  
  <p>and the way I am calling this function is </p>
  
  <pre class="lang-py prettyprint-override"><code>layers_dims = [100,1]
  tf.reset_default_graph()
  with tf.Session() as sess:
    parameters = initialize_parameters(layers_dims)
  </code></pre>
  
  <p>I am getting an error which says that <code>tf.get.variable</code> is not able to take the name of of the variable as <code>parameters['W' + str(l)]</code>. Instead when I use the name like <code>W1</code> or <code>b1</code>, it works fine.</p>
  
  <p>My aim is to initialize my "L" layer neural network and store the parameters in a dictionary named parameters.</p>
  
  <p>Is there any way around it?</p>