title: Defining Error of An Array with Two Index
body: <p>I get an error such as;</p>
  
  <blockquote>
    <p>Traceback (most recent call last):   File
    "C:\Users\SONY\Desktop\deneme.py", line 42, in 
        G[alpha][n]=compute_G(x,n) NameError: name 'G' is not defined</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <pre><code>N = 20
  N_cor = 25
  N_cf = 25
  a = 0.5
  eps = 1.4
  
  def update(x):
      for j in range(0,N):
          old_x = x[j]
          old_Sj = S(j,x)
          x[j] = x[j] + random.uniform(-eps,eps)
          dS = S(j,x) - old_Sj
          if dS&gt;0 and exp(-dS)&lt;random.uniform(0,1):
              x[j] = old_x
  
  def S(j,x):
      jp = (j+1)%N
      jm = (j-1)%N
      return a*x[j]**2/2 + x[j]*(x[j]-x[jp]-x[jm])/a
  
  def compute_G(x,n):
      g = 0
      for j in range(0,N):
          g = g + x[j]*x[(j+n)%N]
          return g/N
  
  #def MCaverage(x,G):
  import random
  from math import exp
  x=[]
  for j in range(0,N):
      x.append(0.0)
      print"x(%d)=%f"%(j,x[j])
  for j in range(0,5*N_cor):
      update(x)
  for alpha in range(0,N_cf):
      for j in range(0,N_cor):
          update(x)
          for i in range(0,N):
              print"x(%d)=%f"%(i,x[i])        
      for n in range(0,N):
          G[alpha][n]=compute_G(x,n)
  for n in range(0,N):
      avg_G = 0
      for alpha in range(0,N_cf):
          avg_G = avg_G + G[alpha][n]
          avg_G = avg_G / N_cf
          print "G(%d) = %f"%(n,avg_G)
  </code></pre>
  
  <p>When i define G I get another error such as:</p>
  
  <blockquote>
    <p>Traceback (most recent call last):   File
    "C:\Users\SONY\Desktop\deneme.py", line 43, in 
        G[alpha][n]=compute_G(x,n) IndexError: list index out of range</p>
  </blockquote>
  
  <p>Here is how i define G:</p>
  
  <pre><code>...
  for alpha in range(0,N_cf):
      for j in range(0,N_cor):
          update(x)
      for n in range(0,N):
          G=[][]
          G[alpha][n]=compute_G(x,n)
  ...
  </code></pre>
  
  <p>What should i do to define an array with two index ie a two dimensional matrix?</p>