0

Dear Python community,

I have Data in an X Y shape in a List.

xy = [[962, 656], [960, 492], [630, 658], [714, 656], [794, 742], [794, 576], [880, 656], [962, 574], [712, 740], [630, 490], [878, 492], [712, 824], [962, 740], [798, 824], [630, 742], [878, 572], [796, 490], [960, 822], [878, 740], [630, 574], [796, 656], [630, 824], [712, 492], [876, 824], [712, 574]]

Image/Plot of the Data:

I would like to sort the Data because they will be measured in random order. The point in the upper left-hand corner should be always in the first or last position in the end.

I Found a Stackoverflow post about it. How to sort a list of x-y coordinates

It helped. Now my question I would like to sort the Data with a Delta so that means for example 712 and 714 are in the same Group (treated as equal). That means I want them in the same Row(or Colum). The measurements are a bit noisy. The xy Positions are Position in an Image. I will analyze multiple Images. The sorting for the Objekts should be in the same order each time. The Upper left-Hand corner should be number one(852, 490). When the next dataPoint is like 740, 492 the sorting Algorithms won´t sort it in the same row (because 490 and 492 are different). That is my problem. This is why I thought about a delta... But maybe one of you will find a smarter solution..

 # code from other post 
 new_xy = sorted(xy , key=lambda k: [(k[0]), (k[1])])
 

 # something like 
 delta = +/- 5 
 new_xy = sorted(xy , key=lambda k: [(k[0] + delta), (k[1] + delta)])

Any help would be appreciated.

Thank you very much :)

  • What's your question? What's the problem with this code? – ForceBru Oct 12 '21 at 14:50
  • Suppose you're using a delta of 5 like in the example here, and you have data points for 100, 104 and 108. 100 and 104 are within this delta from each other, as are 104 and 108. Would you consider all three of them as the same data point? Do something different? – Mureinik Oct 12 '21 at 14:50
  • 1
    It probably makes more sense to sort your data and then add noise by shuffeling – mapf Oct 12 '21 at 14:50
  • Why are they treated as equal? For which value of delta is this? – Dani Mesejo Oct 12 '21 at 14:52
  • Comparison with a delta does not meet strict weak ordering. – Kenny Ostrom Oct 12 '21 at 14:57
  • see https://stackoverflow.com/questions/18291620/why-will-stdsort-crash-if-the-comparison-function-is-not-as-operator – Kenny Ostrom Oct 12 '21 at 15:06

0 Answers0