I am trying to pass a 2d array of sorted values and a 1d array of values to searchsortedand return a corresponding 1d array of index values to it. I have to perform this operation many times, and I am trying to find an effective way to do this. Ultimately, I would like to pass a 3D array of values sorted by axis, a 2-dimensional array of values to search for and return the function to a 2d index array.
Here MLE
from numpy import *
random.seed(1234)
a = zeros((4,10))
a[:,1:-1] = random.rand(4,8)
a[:,1:-1].sort(1)
a[:,-1] = 1.
v = random.rand(4)
res = array([searchsorted(a[j], v[j]) for j in xrange(4)])
where resshould be [9, 1, 7, 6]
Is there an effective way to do this? Ideally, I would like to avoid Cython, if at all possible. If this helps, each array found should have 9-10 elements, while the number of searched values is greater (100-1000 elements), so the transmitted 2d array will have a size of 1000x10.
MLE