title: NumPy array indexing a 4D array
body: <p>I have a 4D array 'a' of size (2,3,4,4) filled with zeros.</p>
  
  <pre class="lang-py prettyprint-override"><code>import numpy as np
  a = np.zeros((2,3,4,4))
  </code></pre>
  
  <p>I also have a 3D array 'b' of size(2,3,4) that carries some index values (all between 0 and 3). </p>
  
  <p>What I want to do is replace the element of every last array in 'a' (the 4th dimension of 'a') that corresponds to the index in 'b', with 1.</p>
  
  <p>I can do this with 3 for loops, as shown below:</p>
  
  <pre class="lang-py prettyprint-override"><code>for i in a.shape[0]:
      for j in a.shape[1]:
          for z in a.shape[2]:
              a[i,j,z][b[i,j,z]] = 1 
  </code></pre>
  
  <p>But I was wondering if there is anyway I can avoid looping at all. Something similar to:</p>
  
  <pre class="lang-py prettyprint-override"><code>a[b] = 1
  </code></pre>