Posts

Showing posts with the label closest-points

algorithm, closest point between list elements

algorithm, closest point between list elements I have n ordered lists of unequal size (where I do not know beforehand how many lists there are going to be). I need to find the minimum average distance between one element in each list. For example given n=3 for three lists: a = [14, 22, 36, 48] b = [14, 23, 30, 72] c = [1, 18, 24] The output should be (22,23,24) because: mean(abs(22-23), abs(23-24), abs(22-24)) = 1.33333 which is the smallest among all the points in the example above. I tried to implement it in Python as following def alligner(aoa): ''' read arrays of arrays of peaks and return closest peaks ''' #one of arrays is empty if not [y for x in aoa for y in x]: return None # there is the same nr in all array no need to do anything candidate = set.intersection(*map(set, aoa)) if candidate: # returns intersect return [max(list(candidate))] * len(aoa) else: #tried cartesian product via bumpy malloc err pass My doubt is now regarding the...