List enumeration is a very inefficient way to work with numpy arrays. They are a particularly poor choice for distance calculation.
To find the difference between your data and a point, you simply execute data - point . Then you can calculate the distance using np.hypot , or if you want, put a square, sum it up and take the square root.
This is a little easier if you make it an Nx2 array for calculation purposes.
Basically, you want something like this:
import numpy as np data = np.array([[[1704, 1240], [1745, 1244], [1972, 1290], [2129, 1395], [1989, 1332]], [[1712, 1246], [1750, 1246], [1964, 1286], [2138, 1399], [1989, 1333]], [[1721, 1249], [1756, 1249], [1955, 1283], [2145, 1399], [1990, 1333]]]) point = [1989, 1332]
This gives:
array([[[ 299.48121811], [ 259.38388539], [ 45.31004304], [ 153.5219854 ], [ 0. ]], [[ 290.04310025], [ 254.0019685 ], [ 52.35456045], [ 163.37074401], [ 1. ]], [[ 280.55837182], [ 247.34186868], [ 59.6405902 ], [ 169.77926846], [ 1.41421356]]])
Deleting the closest element is now a little more complicated than just getting the closest element.
With numpy, you can use boolean indexing to make this pretty easy.
However, you need to worry a bit about aligning your axes.
The key is to understand that numpy "translates" operations along the last axis. In this case, we want to roam the middle axis.
In addition, -1 can be used as a placeholder for axis size. Numpy will calculate the allowable size when -1 is placed as the axis size.
What we need to do, it will look something like this:
#-- Remove closest point --------------------- mask = np.squeeze(dist) != dist.min(axis=1) filtered = data[mask]
You can do this in one line, I just break it down into readability. The key is that dist != something produces a boolean array that can then be used to index the original array.
So, all together:
import numpy as np data = np.array([[[1704, 1240], [1745, 1244], [1972, 1290], [2129, 1395], [1989, 1332]], [[1712, 1246], [1750, 1246], [1964, 1286], [2138, 1399], [1989, 1333]], [[1721, 1249], [1756, 1249], [1955, 1283], [2145, 1399], [1990, 1333]]]) point = [1989, 1332]
Productivity:
array([[[1704, 1240], [1745, 1244], [1972, 1290], [2129, 1395]], [[1712, 1246], [1750, 1246], [1964, 1286], [2138, 1399]], [[1721, 1249], [1756, 1249], [1955, 1283], [2145, 1399]]])
On the side of the note, if more than one point is equally close, this will not work. Massive arrays must have the same number of elements along each dimension, so in this case you will need to re-group.