title: Numpy indexing 3-dimensional array into 2-dimensional array
body: <p>I have a three-dimensional array of the following structure:</p>
  
  <pre><code>x = np.array([[[1,2],
                 [3,4]],
                [[5,6],
                 [7,8]]], dtype=np.double)
  </code></pre>
  
  <p>Additionally, I have an index array</p>
  
  <pre><code>idx = np.array([[0,1],[1,3]], dtype=np.int)
  </code></pre>
  
  <p>Each row of <code>idx</code> defines the row/column indices for the placement of each sub-array along the <code>0</code> axis in <code>x</code> into a two-dimensional array <code>K</code> that is initialized as</p>
  
  <pre><code>K = np.zeros((4,4), dtype=np.double)
  </code></pre>
  
  <p>I would like to use fancy indexing/broadcasting to performing the indexing without a <code>for</code> loop. I currently do it this way:</p>
  
  <pre><code>for i, id in enumerate(idx):
  
      idx_grid = np.ix_(id,id)
  
      K[idx_grid] += x[i]
  </code></pre>
  
  <p>Such that the result is:</p>
  
  <pre><code>&gt;&gt;&gt; K = array([[ 1.,  2.,  0.,  0.],
                 [ 3.,  9.,  0.,  6.],
                 [ 0.,  0.,  0.,  0.],
                 [ 0.,  7.,  0.,  8.]])
  </code></pre>
  
  <p>Is this possible to do with fancy indexing?</p>