title: Use list of lists to average rows in numpy array
body: <p>I want to use information from entries in a (python) list of lists to average rows of a numpy array. For example, consider the following:</p>
  
  <pre><code>LoL = [[], [0, 1, 2, 4], [3, 5], [], [6]]  #List of lists
  arr = np.array([[0, 0, 0, 0], [1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]])  #Numpy array
  print arr
  
  [[0 0 0 0]
   [1 1 1 1]
   [2 2 2 2]
   [3 3 3 3]
   [4 4 4 4]
   [5 5 5 5]
   [6 6 6 6]]
  </code></pre>
  
  <p>For the above list of lists (<code>LoL</code>) and numpy array (<code>arr</code>), I would like rows <code>[0, 1, 2, 4]</code> of <code>arr</code> to get averaged, rows <code>[3, 5]</code> of <code>arr</code> to get averaged between themselves and row <code>[6]</code> to stay in its original form. The transformed array (<code>arr_new</code>) should look like the following:</p>
  
  <pre><code>arr_new = np.array([[1.75, 1.75, 1.75, 1.75], [4.0, 4.0, 4.0, 4.0] , [6.0, 6.0, 6.0, 6.0]])
  print arr_new
  
  [[1.75 1.75 1.75 1.75]
   [4.   4.   4.   4.  ]
   [6.   6.   6.   6.  ]]
  </code></pre>
  
  <p>What is the most elegant way to do this?</p>