code: def get_by_index(x, idx):
      assert len(x.get_shape()) == 2
      assert len(idx.get_shape()) == 1
      idx_flattened = tf.range(0, x.shape[0]) * x.shape[1] + idx
      y = tf.gather(
          tf.reshape(x, [-1]), idx_flattened  # flatten input
      )  # use flattened indices
      return y
  
imports: import os
  import numpy
  import tensorflow
  from collections import deque
label_desc: Use image node_id 21 for calling a global function with example usage: get_by_index(x, idx) and returns: y