title: Creating a slice of a matrix from a vector in Numpy
body: <p>Provided that I have a matrix <code>A</code> of size 5 by 4, also a vector <code>b</code> of length 5 whose element indicates how many values I need in the corresponding row of matrix <code>A</code>. That means each value in <code>b</code> is upper-bounded by the size of second dimension of <code>A</code>. My problem is how to make a slice of a matrix given an vector, which is a complex-version of taking an integer-valued elements of a vector by writing <code>vector[:n]</code></p>
  
  <p>For example, this can be implemented with a loop over A's rows:</p>
  
  <pre><code>import numpy
  A=numpy.arange(20).reshape((5,4))
  b=numpy.array([0, 3, 3, 2, 3])
  output=A[0, :b[0]]
  for i in xrange(1, A.shape[0]):
      output=numpy.concatenate((output, A[i, :b[i]]), axis=0)
  # output is array([ 4,  5,  6,  8,  9, 10, 12, 13, 16, 17, 18])
  </code></pre>
  
  <p>The computation efficiency of this loop can be fairly low when dealing with a very large array. Furthermore, my purpose is to apply this in Theano eventually without a <code>scan</code> operation. I want to avoid using a loop to make a slice given an vector.</p>