I have an array a = [1, 2, 3, 4, 5, 6] and b = [1, 3, 5] , and I would like to display a in such a way that for each element from a between the elements in b it will be mapped to index b is the top range that contains a . Not the best explanation in words, but an example
a = 1 -> 0 because a <= first element of b a = 2 -> 1 because b[0] < 2 <= b[1] and b[1] = 3 a = 3 -> 1 a = 4 -> 2 because b[1] < 4 <= b[2]
So the final product I want is f(a, b) = [0, 1, 1, 2, 2, 2]
I know that I can just go in cycles and decide for it, but I was wondering if there is a smart, fast (vectorized) way to do this in pandas / numpy
source share