I'm trying to figure out an efficient way of taking a numpy array of float values and converting them to an index associated with a specific range.
eg numpy array of x floats [ -999.99, 433.000, -56.00....] (this array is actually quite large typically from 6000 to 25000 values.
The range info effectively consists of a much smaller around 3 to 20 rows (y) of range start values (arranged in ascending sequence) . eg [-9999.0, 0.0, 0.0, 500.0 99999.0]. A value can be repeated as shown with the 0.0 value.
This is then used to build a set of ranges such that start of the range = [:yrows - 2] and end = [1:yrows -1] such that this gives a series of ranges [(-9999.0, 0.0), (0.0, 0.0), (0.0, 500.0), (500.0, 99999.0) with a total number of rows of yrows -1 (an index can then be generated corresponding to each row
What I need to derive is then the equivalent of the index of the y row that the original x float value was in (there will be only one per x float). I will then use the index to derive further information associated with that specific range.
eg indexes of [ -999.99, 433.000, -56.00....] would yield indexvalues[ 0, 2, 0...] Note for clarity the x values are not in any way sorted but will always be larger than the lowest array range value and smaller than the highest array range value.
The indexing would work such that the required index is one where x >= range start and less than range end thus the (0.0, 0.0) entry above is a range that will never get picked and are there to create new end/start attributes of the previous, next ranges only.
OK This was resolved. The numpy.digitize does exactly what I need eg numpy.digitize(xfloatarray, ybins, right=False).
I just hadn't come across the function and couldn't google a find to the function until after posting... I just kept getting results about splitting arrays or creating indexes.