We are trying to create group of co-ordinates which are in close range of each other. To create this group we need to compare x, y co-ordinates of numpy array with the 1st element in the arrary.
If they match we store that in one in an existing array and if not we create a new one and store them there.
We have tried it with a for loop and extract x and y seperately. But, it didnt work.
mport numpy as np
coordinates = [(580.4625,201.87183),(580.4625,201.87183),(167.84459,701.64935),
(167.84459,701.64935),(167.84459,694.65247),(167.84459,694.65247),
(979.09344,725.6387),(979.09344,725.6387),(979.09344,725.6387),
(979.09344,725.6387),(200.81406,1271.3956),(200.81406,1271.3956),
(200.81406,1271.3956),(1005.0694,1266.398),(1005.0694,1266.398),
(1005.0694,1266.398),(180.83257,1568.2635),(180.83257,1568.2635),
(994.0796,1591.2533),(539.5005,1862.1327)]
seen = set()
newlist = []
for item in coordinates:
t = tuple(item)
if t not in seen:
newlist.append(item)
seen.add(t)
npArray = np.array(newlist)
newlist = npArray.astype(int)
npArray2 = np.array(newlist)
coordinates1 = npArray2.astype(int)
for i in coordinates1[0]:
print(i[0])
We are trying to get the 1st element of the co-ordinates in above message in a seperate variable.
Currently we are getting an error: IndexError: invalid index to scalar variable.
We are new to python, so any guidence will be helpful, even if pointer to a better way of doing this.
Thanks!
Thank you for all the answers. I think my mistake is in not explaning the question. I will try here again:
coordinates = [(580.4625,201.87183),(580.4625,201.87183),(167.84459,701.64935),
(167.84459,701.64935),(167.84459,694.65247),(167.84459,694.65247),
(979.09344,725.6387),(979.09344,725.6387),(979.09344,725.6387),
(979.09344,725.6387),(200.81406,1271.3956),(200.81406,1271.3956),
(200.81406,1271.3956),(1005.0694,1266.398),(1005.0694,1266.398),
(1005.0694,1266.398),(180.83257,1568.2635),(180.83257,1568.2635),
(994.0796,1591.2533),(539.5005,1862.1327)]
We are trying to create groups of co-ordinates which are in proximity/range of 30 points + or - of the 1st co-odinate in the above list.
So, for that we will need to compare all co-ordinates (x, y) one by one with the 1st co-rdiante and if they are in above said range, we will assign them to an group(eg.G1)/array with 1st co-ordiante as the 1st element in that group.
If not in range, we will create another group(eg.G2)/array and insert the co-ordiante not in range in this new group.
This way we go further comparing one by one each element in above list until all co-ordinates are compared and assigned to one of the groups.
Hope, I made this more clear.
Many thanks for your help!
Best Regards,