title: How do I convert this C code into Python?
body: <p>I am trying to convert this C code I have into a python script so it's readily accessible by more people, but I am having problems understanding this one snippet.</p>
  
  <pre><code>int i, t;
  for (i = 0; i &lt; N; i++) {
     t = (int)(T*drand48());
     z[i] = t;
     Nwt[w[i]][t]++;
     Ndt[d[i]][t]++;
     Nt[t]++;
  }
  </code></pre>
  
  <p>N is a value (sum of one column from an array. Elemental corrected me).</p>
  
  <p>T is just a numerical value.</p>
  
  <p>z, w, and d are memory allocations created from the N array. They were created with this method.</p>
  
  <pre><code>w = ivec(N);
  d = ivec(N);
  z = ivec(N);
  
  int *ivec(int n) //
  {
     int *x = (int*)calloc(n,sizeof(int));
     assert(x);
     return x;
  }
  </code></pre>
  
  <p>Nwt &amp; Ndt are both arrays too, with each element being a memory allocation? (Not sure). At least, each one of them was created by using the following method, passing in two different int's.</p>
  
  <pre><code>Nwt = dmat(W,T);
  Ndt = dmat(D,T);
  
  double **dmat(int nr, int nc) //
  {
     int N = nr*nc;
     double *tmp = (double*) calloc(N,sizeof(double));
     double **x  = (double**)calloc(nr,sizeof(double*));
     int r;
     assert(tmp);
     assert(x);
     for (r = 0; r &lt; nr; r++) x[r] = tmp + nc*r;
     return x;
  }
  </code></pre>
  
  <p>So looking at the first loop I posted, what are the following lines doing? I would like to accomplish the same thing in python, but since no memory allocation is needed, not sure what those three lines do, or how I would duplicate it in python.</p>
  
  <pre><code>Nwt[w[i]][t]++;
  Ndt[d[i]][t]++;
  Nt[t]++;
  </code></pre>
  
  <p>This is what I have so far:</p>
  
  <pre><code>for i in range(self.N):
          t = self.T * random.random()
          self.z[i] = t
          //** INCORRECT BELOW **
          //self.Nwt[self.N[i]] = t + 1 
          //self.Ndt[i] = t + 1
          //self.Nt[t + 1] += 1
  </code></pre>