title: assigning values in a numpy array
body: <p>I have a numpy array of zeros. For concreteness, suppose it's 2x3x4:</p>
  
  <pre><code>x = np.zeros((2,3,4))
  </code></pre>
  
  <p>and suppose I have a 2x3 array of random integers from 0 to 3 (the index of the 3rd dimension of x).</p>
  
  <pre><code>&gt;&gt;&gt; y = sp.stats.distributions.randint.rvs(0, 4, size=(2,3))
  &gt;&gt;&gt; y
  [[2 1 0]
   [3 2 0]]
  </code></pre>
  
  <p>How do I do the following assignments efficiently (edit: something that doesn't use for loops and works for x with any number of dimensions and any number of elements in each dimension)? </p>
  
  <pre><code>&gt;&gt;&gt; x[0,0,y[0,0]]=1
  &gt;&gt;&gt; x[0,1,y[0,1]]=1
  &gt;&gt;&gt; x[0,2,y[0,2]]=1
  &gt;&gt;&gt; x[1,0,y[1,0]]=1
  &gt;&gt;&gt; x[1,1,y[1,1]]=1
  &gt;&gt;&gt; x[1,2,y[1,2]]=1
  &gt;&gt;&gt; x
  array([[[ 0.,  0.,  1.,  0.],
          [ 0.,  1.,  0.,  0.],
          [ 1.,  0.,  0.,  0.]],
  
         [[ 0.,  0.,  0.,  1.],
          [ 0.,  0.,  1.,  0.],
          [ 1.,  0.,  0.,  0.]]])
  </code></pre>
  
  <p>Thanks,
  James</p>