1

I have a numpy matrix of the following format:

A = [[10, 20, 30, 40, 50]
     [100, 200, 300, 400, 600]
     [60, 70, 80, 90, 100]]

In this I want to do a binary search individually on each row using another numpy array B which has as many elements as the number of rows for A.

B = [45, 220, 95]

The search results should yield the following with each element signifying the index of the element lower than that value B.

f(A, B) = [3, 1, 3]

What is the best way to do this using numpy operations with lowest runtime possible? Do I have to use something like vectorize or is there some other natural way to do this?

If there is no way to do this using native numpy operations, then is it possible to do this for a simplified problem where B is not an array but a single value and we have to perform binary search on each row with this element and find the indices where B could be found in each row.

Karthik Prakash
  • 153
  • 4
  • 11

0 Answers0