title: Build sum of array based on index array
body: <p>I have three arrays</p>
  
  <pre><code>A = array([0, 0, 0, 0])
  
  B = array([0.4, 0.3, 0.2, 0.1])
  
  C = array([0, 0, 1, 2])
  </code></pre>
  
  <p>I want to assign to every element i of array A the sum of all elements of array B for which array C points to i. The result should be</p>
  
  <pre><code>A = array([0.7, 0.2, 0.1, 0])
  </code></pre>
  
  <p>So far I get the desired result as follows:</p>
  
  <pre><code>for i in np.unique(C):
   A[i] = np.sum(B[C==i])
  </code></pre>
  
  <p>The arrays are large, and the loop is slow. I am trying to accomplish this without a loop, but I don't know how. Thank you for suggestions!</p>