title: Filtering coordinate points on the basis of nearest distance
body: <p>I have a numpy array which contains coordinates points like this</p>
  
  <pre><code>[[ 581  925]
   [ 582  926]
   [ 582  931]
   [ 582  939]
   [ 584  933]
   [ 584  937]
   [ 585  943]
   [ 586  944]
   [ 589  944]]
  </code></pre>
  
  <p>As you can see there are points which have same x coordinates but different y coordinates. <strong>Starting from the first coordinate, distance to the next closest immediate coordinate is calculated.</strong> 
  <br>Like for example, <strong>distance from <code>[581 925]</code> to next nearest coordinate is found out. The candidates are <code>[ 582  926], [ 582  931] &amp; [ 582  939]</code> since these are the immediate coordinates which are the closest to <code>[581 925]</code>.</strong> </p>
  
  <p>As it's obvious in this case that <code>[582 926]</code> is the nearest coordinate to <code>[581 925]</code>, I only want that coordinate to exist and the other 2 candidate coordinates to be deleted. So the resultant array should be</p>
  
  <pre><code>[[ 581  925]
   [ 582  926]
        .
        .
        .
   [ 589  944]]
  </code></pre>
  
  <p>Now same operation should be performed starting from <code>[582  926]</code> and so on till the end.</p>
  
  <p>Contour with unfiltered coordinates:<br>
  <a href="https://i.imgur.com/pYzy9L3.png" rel="nofollow noreferrer"><img src="https://i.imgur.com/pYzy9L3.png" alt="enter image description here"></a></p>
  
  <p>Contour with filtered coordinates:<br>
  <a href="https://i.imgur.com/Do25pb6.png" rel="nofollow noreferrer"><img src="https://i.imgur.com/Do25pb6.png" alt="enter image description here"></a></p>
  
  <p><strong>What is the most pythonic (favorably numpy) approach for this with the least time complexity since it's of the utmost concern?</strong></p>
  
  <p>NOTE: Line Thinning is not of concern, only concern is of removing the unnecessary points/coordinates.</p>