The aim here is speed- I am trying to get away from looping through the arrays in question. It can however be assumed that the two arrays are sorted.
a = np.arange(10)
b = np.array([2.3, 3.5, 5.8, 13])
c = somefunc(a,b)
Now somefunc should find the indices of a for which the values in b are closest too, i.e.
In []: c
Out[]: array([2, 3or4, 6, 9]) #3 or 4 depending on python2 or 3
Once again, this could be done with a loop, but I am looking for something a lot faster. I got quite close by taking the absolute difference type approach, something like:
np.argmin(np.abs(a[:, np.newaxis] - b), axis=0)
But even this is a little slow as a lot of unnecessary subtractions are done.
cto bearray([2, 3, 6, 9]), because you're comparing witharange(10), which starts from 0.argminresult doesn't give a single index perbvalue? It does for me...[2,4,6,9]instead?[2, 3 or 4, 6, 9]depending on it is is python 2 or 3.