title: Slicing an [m, n] array by a variable [m] array in numpy
body: <p>Let there be a numpy array of shape [M], dtype int32 and (random) values in range [0, N), e.g.:</p>
  
  <pre><code>M = 8
  N = 5
  a = np.random.randint(0, N, [M])  # a = [1, 1, 2, 4, 0, 1, 1, 3]
  </code></pre>
  
  <p>From this array I need to create a matrix m of shape [M, N], dtype int32 and values 0 or 1, where m[i,j] = 0 if j &lt; a[i], otherwise 1. Following the example:</p>
  
  <pre><code>m = some_magic(a)     # m = [[0, 1, 1, 1, 1],
                        #      [0, 1, 1, 1, 1],
                        #      [0, 0, 1, 1, 1],
                        #      [0, 0, 0, 0, 1],
                        #      [1, 1, 1, 1, 1],
                        #      [0, 1, 1, 1, 1],
                        #      [0, 1, 1, 1, 1],
                        #      [0, 0, 0, 1, 1]]
  </code></pre>
  
  <p>My dysfunctional version of <em>some_magic</em> starts with initializing the matrix to zeros (using np.zeros), and then proceeding to set the appropriate members to 1.</p>
  
  <pre><code>m = np.zeros([M, N])
  </code></pre>
  
  <p>This next part though I cannot properly figure out. Accessing single members, for example, every second member, or a fixed slice, is easy, and achievable by</p>
  
  <pre><code>m[np.arange(M), C1:C2]
  </code></pre>
  
  <p>where C1 and C2 are integer constants,</p>
  
  <pre><code>m[np.arange(M), a:]
  </code></pre>
  
  <p>which, as far as I've thought, should yield the correct result, fails with the error being</p>
  
  <pre><code>Only integer scalar arrays can be converted to a scalar index.
  </code></pre>
  
  <p>Can you please point me to the right direction? Thank you very much.</p>