title: How does the parameter 'dim' in torch.unique() work?
body: <p>I am trying to extract the unique values in each row of a matrix and returning them into the same matrix (with repeated values set to say, 0) For example, I would like to transform</p>
  
  <pre><code>torch.Tensor(([1, 2, 3, 4, 3, 3, 4],
                [1, 6, 3, 5, 3, 5, 4]])
  </code></pre>
  
  <p>to</p>
  
  <pre><code>torch.Tensor(([1, 2, 3, 4, 0, 0, 0],
                [1, 6, 3, 5, 0, 0, 4]])
  </code></pre>
  
  <p>or </p>
  
  <pre><code>torch.Tensor(([1, 2, 3, 4, 0, 0, 0],
                [1, 6, 3, 5, 4, 0, 0]])
  </code></pre>
  
  <p>I.e. the order does not matter in the rows. I have tried using <code>pytorch.unique()</code> and in the documentation it is mentioned that the dimension to take the unique values can be specified with the parameter <code>dim</code>. However, It doesn't seem to work for this case. </p>
  
  <p>I've tried:</p>
  
  <pre><code>output= torch.unique(torch.Tensor([[4,2,52,2,2],[5,2,6,6,5]]), dim = 1)
  
  output
  </code></pre>
  
  <p>Which gives</p>
  
  <pre><code>tensor([[ 2.,  2.,  2.,  4., 52.],
          [ 2.,  5.,  6.,  5.,  6.]])
  </code></pre>
  
  <p>Does anyone have a particular fix for this? If possible, I'm trying to avoid for loops. </p>