Is tf.gather enought for your use case?

  
      

      TensorFlow
  

  
    

tf.gather  |  TensorFlow Core v2.5.0 2

  Gather slices from params axis axis according to indices. (deprecated arguments)


  

  
    
    
  

  


Then we have also tf.gather_nd:

  
      

      TensorFlow
  

  
    

tf.gather_nd  |  TensorFlow Core v2.5.0 2

  Gather slices from params into a Tensor with shape specified by indices.