title: How can I use the index array in tensorflow?
body: <p>If given a matrix <code>a</code> with shape <code>(5,3)</code> and index array <code>b</code> with shape <code>(5,)</code>, we can easily get the corresponding vector <code>c</code> through,</p>
  
  <p><code>c = a[np.arange(5), b]</code></p>
  
  <p>However, I cannot do the same thing with tensorflow,</p>
  
  <pre><code>a = tf.placeholder(tf.float32, shape=(5, 3))
  b = tf.placeholder(tf.int32, [5,])
  # this line throws error
  c = a[tf.range(5), b]
  </code></pre>
  
  <blockquote>
    <p>Traceback (most recent call last):   File "", line 1, in
       File
    "~/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py",
    line 513, in _SliceHelper
        name=name)</p>
    
    <p>File
    "~/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py",
    line 671, in strided_slice
        shrink_axis_mask=shrink_axis_mask)   File "~/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py",
    line 3688, in strided_slice
        shrink_axis_mask=shrink_axis_mask, name=name)   File "~/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py",
    line 763, in apply_op
        op_def=op_def)   File "~/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py",
    line 2397, in create_op
        set_shapes_for_outputs(ret)   File "~/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py",
    line 1757, in set_shapes_for_outputs
        shapes = shape_func(op)   File "~/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py",
    line 1707, in call_with_requiring
        return call_cpp_shape_fn(op, require_shape_fn=True)   File "~/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py",
    line 610, in call_cpp_shape_fn
        debug_python_shape_fn, require_shape_fn)   File "~/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py",
    line 675, in _call_cpp_shape_fn_impl
        raise ValueError(err.message) ValueError: Shape must be rank 1 but is rank 2 for 'strided_slice_14' (op: 'StridedSlice') with input
    shapes: [5,3], [2,5], [2,5], [2].</p>
  </blockquote>
  
  <p>My question is, if I cannot produce the expected result in tensorflow as in numpy using the above mentioned method, what should I do?</p>