(Re-edited) For example, I have a list-like array:
l = [0.3, 2.3, 3.1, 4.5] # value can be any numeric type
Then given a number 1.2
, as it is between 0.3 and 2.3
, index 1
should be returned, and given a number 3.3
, which is between 3.1 and 4.5
, index 3
should be returned, for value less than 0.3
, should return index 0
, etc.
Basically for whatever input value, depends on the bin it falls into, return the index of that bin.
I hope not use if else
statement, as the number of items in the list could be huge.
I guess the question should have been asked somewhere, but I just can't locate it.
(BTW, I actually remember there is a built-in function in numpy
does the trick, but I can't recall anymore ...)