1

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?

Tian
  • 870
  • 3
  • 12
  • 24
  • Definitely not the best answer, but this sounds like a suited problem for Numba if a better algorithm is not proposed. – Patol75 Nov 29 '19 at 02:48
  • @Tian So, if the inputs are images, would they be int arrays? If so, we could optimize with that in mind. – Divakar Nov 29 '19 at 05:30
  • For now they are 32 bit floating point images. But the values of the pixels range from 0 - 1.605 if i recall correctly. I am trying to find the spacing between the values so that I can convert them to a 32bit uint image, or even an 8bit uint image if there are no losses – Tian Nov 29 '19 at 05:36

0 Answers0