How to find the largest x,y coordinate among a set of coordinates?

john mathews

I have a set of x,y coordinates and I want to get the largest coordinate value which have the difference less than 0.1.

For example; I have an array which contains both x,y values as below:

array = [6.72, 0.16,13.28, 0.14,13.3, 5.64,6.74, 5.68,6.62, 0.14]

x values -> 6.72,13.28,13.3,6.74,6.62
y values -> 0.16,0.14,5.64,5.68,0.14

If I take x values; 6.72,6.74,6.62 values have difference less than 0.1.
So I want to take the largest value of them. It's 6.74. 13.3, 13.28 also has a difference less than 0.1. So I need to take the largest value, 13.3.
I need to replace 6.72,6.74,6.62 from 6.74 and 13.3, 13.28 from 13.3

I need to do the same thing for y values as well.

My output array should be;

output_array = [6.74, 0.16,13.3, 0.16,13.3, 5.68,6.74, 5.68,6.74, 0.16]
blhsing

You can iterate through sorted coordinate values and keep only the largest of numbers that differ from the preceding numbers by less than 0.1, and map the preceding numbers to the largest numbers.

coords = [6.72, 0.16, 13.28, 0.14, 13.3, 5.64, 6.74, 5.68, 6.62, 0.14]
last_coord = None
unmapped = []
mapping = {}
for coord in sorted(coords):
    if last_coord is not None and coord - last_coord >= 0.1:
        mapping.update(dict.fromkeys(unmapped, last_coord))
        unmapped = []
    unmapped.append(coord)
    last_coord = coord
mapping.update(dict.fromkeys(unmapped, last_coord))
coords = list(map(mapping.get, coords))
print(coords)

This outputs:

[6.74, 0.16, 13.3, 0.16, 13.3, 5.68, 6.74, 5.68, 6.74, 0.16]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Find the closest coordinate from a set of coordinates

How to find new coordinates with initial coordinate and distance?

How to find y coordinate on line B with respective x coordinate of line A

How to find upper-left coordinate in an array of coordinates in java

geopandas POLYGON coordinates to x,y coordinate columns

How to return x value from (x,y) coordinates in a set

How to convert relative GPS coordinates to a "local custom" x, y, z coordinate?

Find largest ones after setting a coordinate to one

How to find the farthest x, y coordinates from many points?

how to find the x and y coordinates of the image points in javascript

How to find velocity of tennis ball if I have x,y coordinates?

How to store and use a large set of X and Y coordinates In visual basic

how to set x and y coordinates in image manipulation.

Python Graphics library: How to set the x and y coordinates of the window?

How to set the position of textView using X and y coordinates

Given a set of intervals, how to find the maximum number of intersections among them,

MATLAB: Extracting x coordinate that matches up with largest y value

Storing (x, y) Coordinates with set

how to swap the first digit(if not largest among the digits) with largest digit in an integer

Calculating the two x coordinates at edge of circle for a specific y coordinate

Find the nearest X,Y coordinate using R

How does one pick the col/row or x/y coordinates of N random elements of a 2D matrix without item/coordinate duplicates?

Find the coordinates of the triangle containing the largest number of points

How to generate a set of random points within a given (x,y) coordinates in an x-y plane?

Find files recursively, but choose largest from among those with duplicate names

Substract every element in an array and find the largest among them

Large set of x,y coordinates. Efficient way to find any within certain distance of each other?

How do you find x,y coordinate of based on the edge of a circle by looking at my mouse cursor

Need help understanding how a line of code is using a maximum y coordinate to find the corresponding X value in python