title: Sum values according to an index array
body: <p>I have two arrays of the same dimension:</p>
  
  <pre><code>a = np.array([ 1,  1, 2,  0, 0, 1])
  b = np.array([50, 51, 6, 10, 3, 2])
  </code></pre>
  
  <p>I want to sum the elements of <code>b</code> according to the indices in <code>a</code>.</p>
  
  <p>The <code>i</code>th element of the matrix I want will be the sum of all values <code>b[j]</code> such that <code>a[j]==i</code>.</p>
  
  <p>So the result should be a 3-dimensional array of <code>[10 + 3, 50 + 51 + 2, 6]</code></p>
  
  <p>Is there a numpy way to do this? I have some very large arrays that I need to sum like this over multiple dimensions, so it would NOT be convenient to to have to perform explicit loops.</p>