Take for example two arrays
a = np.array([1, 2, 3, 4])
b = np.array([3.5, 5, 6, 7])
The smallest spacing can be found between both the 3rd and 4th element in a
and the 1st element in b
. The value of interest is 0.5
.
A brute force method would be to iterate through every value in a
and b
, and find the minimal value. But this is computationally heavy if the arrays are large; e.g. flatted images.
Are there more efficient ways to determine the value?