Quantcast
Channel: Numpy data points region/circle - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Numpy data points region/circle

$
0
0

I have a numpy array dat holding x/y values which are plotted later on:

[    [1 2 3 4 5]    [2 4 6 8 10]]

dat[0] holds x-values,dat1 contains the corresponding y-alues.

Now I want to know which data points have neighbors in a specific range (e.g. 5),so I did the following e.g. for point 0 (x=1, y=2):

numpy.where(    (dat[0] > dat[0][0] - 5)&    (dat[0] < dat[0][0] + 5)&    (dat[1] > dat[1][0] - 5)&    (dat[1] < dat[1][0] + 5))

This works but the specified range/region is a square of size 10x10, I would like to havea circle.

My next attempt was to filter data with a vector between the points (where the vector length has to be smaller than 5) which works fine with two points but I can not figure out the right numpy.where statement for this.

For two points it is simply:

math.sqrt( (x_p1 - x_p2)**2 + (y_p1 - y_p2)**2 ) < 5

But how does the equivalent numpy.where would look like?I want to execute this on the whole array and not over and over again for just two points.

To visualize and hopefully clarify the problem:

enter image description here

p1 is one point out of my data and I want to get all green points which are in the circle with the radius of 5, the red points should be filtered.

The above solution with the length of the vector only achieves this for two points, I want this to work on the whole array so that I can for-loop with numpy.where to get all neighbors < 5 for every point in the array.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images