Are you looking for something like:

  

      github.com/tensorflow/tensorflow
  

  
    
  
	  
  

  
    
      [Feature request] np.random.choice analogue 2
    

    
      
        opened 
        
          
        
        Mar 17, 2017
      
      

        
          closed 
        
          
        
        Jun 17, 2017
      
        

      
        
          
          persiyanov
        
      
    

    
        stat:contributions welcome
    
  


  
    TF has no analogue to `np.random.choice` function that chooses random element fr…om tensor (optionally according to provided probabilities). It's especially useful in RL problems when you use epsilon-greedy exploration strategy.

### What related GitHub issues or StackOverflow threads have you found by searching the web for your problem?
[These](http://stackoverflow.com/questions/41123879/numpy-random-choice-in-tensorflow) [two](http://stackoverflow.com/questions/37757986/weighted-random-tensor-select-in-tensorflow) solve the problem using `tf.multinomial`, but maybe it will be convenient to include `tf.random_choice` in TF API?

It could be implemented through `tf.multinomial` , for example.
  

  

  
    
    
  

  


See also:

  

      github.com/tensorflow/tensorflow
  

  
    
  
	  
  

  
    
      Sampling from a categorical distribution without replacement 1
    

    
      
        opened 
        
          
        
        Apr 17, 2017
      
      


      
        
          
          danijar
        
      
    

    
        stat:contributions welcome
        type:feature
    
  


  
    Both `tf.multinomial()` and `tf.contrib.distributions.Categorical.sample()` allo…w to sample from a multinomial distribution. However, they only allow sampling with replacement.

In constrast, Numpy's `numpy.random.choice()` has a `replace` parameter that allows sampling without replacement. Would it be possible to add a similar functionality to TensorFlow?

One use case is sampling examples from the dataset proportional to the model's last loss on them. When an example generates a very large loss, the next batch will mainly consist of that example. Using sampling without replacement, we can avoid this problem.

I see that sampling with replacement can be parallelized and implemented in a vectorized way, but I don't think sampling speed is a bottleneck in most people's programs.