Here’s a potential solution:

  
      stackoverflow.com
  
  
      
    
  

  How to randomly set a fixed number of elements in each row of a tensor in PyTorch 36



  pytorch



  
  answered by
  
    Gil Pinsky
  
  on 11:45AM - 02 Oct 20 UTC


  
  
    
    
  
  


More efficient approaches are welcome.