title: Python code become slower after each iteration
body: <p>I have following code which is supposed to do some operation over a vector of data and store the result, my problem is that when I run this code at first each iteration (each outter loop) takes about 12 sec but after some time iteration's time become longer at the end each iteration takes 2 minutes to become complete, I wanna know what's wrong with my code? is this related to the size of memory and the size of array I am keeping? if yes how can I solve it? if no what's the problem?</p>
  
  <p><code>allclassifiers</code> is 2D vectors: <code>allclassifiers.shape =  tuple: (1020, 1629)</code> which means my for should loop 1629 times and each time do the operation on a vectors of size 1020, each vectors is array 0 or 1s.</p>
  
  <p>At the end the size of <code>points_comb</code> is around 400MB, <code>points_comb.shape = tuple: (26538039, 2)</code>, and I must mention I am running the code on a system with 4GB of RAM.<br>
  <code>valid_list</code> is a vector of 0 and 1 with size of 1020, <code>valid_list.shape tuple: (1020,)</code></p>
  
  <pre><code>startTime = datetime.now()
  
  for i in range(allclassifiers.shape[1]):
      for j in range(allclassifiers.shape[1]):
          rs_t = combine_crisp(valid_list, allclassifiers[:,i], allclassifiers[:,j], boolean_function)
          fpr_tmp, tpr_tmp = resp2pts(valid_list, rs_t)
          points_comb = np.vstack((points_comb,np.hstack((fpr_tmp, tpr_tmp))))
      endTime = datetime.now()
      executionTime = endTime - startTime
      print "Combination for classifier: " + str(i)+ ' ' + str(executionTime.seconds / 60) + " minutes and " + str((executionTime.seconds) - ((executionTime.seconds / 60)*60)) +" seconds"
  
  
  def combine_crisp(lab, r_1, r_2, fun):
  
      rs = np.empty([len(lab), len(fun)])
      k = 0
      for b in fun:
          if b == 1:            #----------------&gt; 'A AND B'
              r12 = np.logical_and(r_1, r_2)
          elif b == 2:            #----------------&gt; 'NOT A AND B'
              r12 = np.logical_not(np.logical_and(r_1, r_2))
          elif b == 3:            #----------------&gt; 'A AND NOT B'
              r12 = np.logical_and(r_1, np.logical_not (r_2))
          elif b == 4:            #----------------&gt; 'A NAND B'
              r12 = np.logical_not( (np.logical_and(r_1, r_2)))
          elif b == 5:            #----------------&gt; 'A OR B'
              r12 = np.logical_or(r_1, r_2)
          elif b == 6:            #----------------&gt; 'NOT A OR B'; 'A IMP B'
              r12 = np.logical_not (np.logical_or(r_1, r_2))
          elif b == 7:            #----------------&gt; 'A OR NOT B' ;'B IMP A'
              r12 = np.logical_or(r_1, np.logical_not (r_2))
          elif b == 8:            #----------------&gt; 'A NOR B'
              r12 = np.logical_not( (np.logical_or(r_1, r_2)))
          elif b == 9:            #----------------&gt; 'A XOR B'
              r12 = np.logical_xor(r_1, r_2)
          elif b == 10:            #----------------&gt; 'A EQV B'
              r12 = np.logical_not (np.logical_xor(r_1, r_2))
          else:
              print('Unknown Boolean function')
  
          rs[:, k] = r12
          k = k + 1
  
  
      return rs
  
  def resp2pts(lab, resp):
      lab = lab &gt; 0
      resp = resp &gt; 0
      P = sum(lab)
      N = sum(~lab)
      if resp.ndim == 1:
          num_pts = 1
          tp = sum(lab[resp])
          fp = sum(~lab[resp])
      else:
          num_pts = resp.shape[1]
          tp = np.empty([num_pts,1])
          fp = np.empty([num_pts,1])
          for i in np.arange(num_pts):
              tp[i] = np.sum( lab[resp[:,i]]) 
              fp[i] = np.sum( ~lab[resp[:,i]])
      tp = np.true_divide(tp,P)
      fp = np.true_divide(fp,N)
      return fp, tp
  </code></pre>