title: Pytorch tensor put z values with x & y coordinates into grid
body: <p>I'm having a torch tensor of shape [3,N], where the three dimensions correspond to x,y,z values, respectively, and N is the number of data points. I.e., the tensor looks like this:</p>
  <pre><code>[x1, y1, z1]
  [x2, y2, z2]
      ...
  [xN, yN, zN]
  </code></pre>
  <p>The x&amp;y values of the tensor correspond to x&amp;y coordinates in an image, while the z value corresponds to the brightness at position [x,y]. Now what I want to do, is to reconstruct the image, based on the values of the tensor.</p>
  <p>Normally, I do this with <code>torch.tensor.put_</code> (<a href="https://pytorch.org/docs/stable/generated/torch.Tensor.put_.html" rel="nofollow noreferrer">Pytorch Reference</a>).</p>
  <p>The problem is, some x&amp;y combinations appear multiple times in the image, i.e. I have multiple color values for a position [x,y], and I only want to keep the highest z-value at each position.</p>
  <p>For example, lets take a 2x2 image. The tensor could then look like this:</p>
  <pre><code>[0,0,1]
  [0,0,3]
  [0,1,0]
  [1,0,1]
  [1,1,1]
  [1,1,3]
  [1,1,5]
  </code></pre>
  <p>And the desired output would then be</p>
  <pre><code>y
  ^
  |  [0, 5]
  |  [3, 1]
  |
  --------&gt; x
  </code></pre>
  <p>Does anyone know how I could achieve this <strong>without iterating over all datapoints N</strong>, similar to the <code>torch.tensor.put_</code> method?</p>