def advanced_indexing_op(input, index):
 batch_size = tf.shape(input)[0]
 max_length = int(input.get_shape()[1])
 dim_size = int(input.get_shape()[2])
 index = ((tf.range(0, batch_size) * max_length) + (index - 1))
 flat = tf.reshape(input, [(-1), dim_size])
 relevant = tf.gather(flat, index)
 return relevant

def advanced_indexing_op ( input , index ) : batch_size = tf . shape ( input ) [ 0 ] max_length = int ( input . get_shape ( ) [ 1 ] ) dim_size = int ( input . get_shape ( ) [ 2 ] ) index = ( ( tf . range ( 0 , batch_size ) * max_length ) + ( index - 1 ) ) flat = tf . reshape ( input , [ ( - 1 ) , dim_size ] ) relevant = tf . gather ( flat , index ) return relevant
advanced indexing for sequences .