Suppose I have 3 numpy
arrays. It could be more than 3 arrays, however.
import numpy as np
INTERVAL = 2
array1 = np.array([1,5,10,15,20,25,30])
array2 = np.array([1,10,50,100,150,200,250,300])
array3 = np.array([3,8,12])
For a given set of elements to match in the above arrays, each element must be within INTERVAL
of each other. The actual index position of the elements in the array do not matter in the comparison. Order is not guaranteed. It is about any element at any position in the arrays are each within INTERVAL
of each other.
Example matches that would be returned from the above 3 arrays:
Example#1
array1 : 1
array2 : 1
array3 : 3
Example#2
array1 : 10
array2 : 10
array3 : 8
Example#3
array1 : 10
array2 : 10
array3 : 12
Bonus points :
In the event where there could be multiple matches with the same elements, only return the one with the lowest sum. For example, Example#2
and Example#3
share elements, but Example#2
& Example#1
should be returned and not Example#3
Any suggestions on how I should go about this?