python - How to efficiently convert numpy values to array of range indexes -


i'm trying figure out efficient way of taking numpy array of float values , converting them index associated specific range.

eg numpy array of x floats [ -999.99, 433.000, -56.00....] (this array quite large typically 6000 25000 values.

the range info consists of smaller around 3 20 rows (y) of range start values (arranged in ascending sequence) . eg [-9999.0, 0.0, 0.0, 500.0 99999.0]. value can repeated shown 0.0 value.

this used build set of ranges such start of range = [:yrows - 2] , end = [1:yrows -1] such gives series of ranges [(-9999.0, 0.0), (0.0, 0.0), (0.0, 500.0), (500.0, 99999.0) total number of rows of yrows -1 (an index can generated corresponding each row

what need derive equivalent of index of y row original x float value in (there 1 per x float). use index derive further information associated specific range.

eg indexes of [ -999.99, 433.000, -56.00....] yield indexvalues[ 0, 2, 0...] note clarity x values not in way sorted larger lowest array range value , smaller highest array range value.

the indexing work such required index 1 x >= range start , less range end (0.0, 0.0) entry above range never picked , there create new end/start attributes of previous, next ranges only.

ok resolved. numpy.digitize need eg numpy.digitize(xfloatarray, ybins, right=false).

i hadn't come across function , couldn't google find function until after posting... kept getting results splitting arrays or creating indexes.

ok resolved. numpy.digitize need, e.g.

numpy.digitize(xfloatarray, ybins, right=false) 

where xfloatarray array of floats [ -999.99, 433.000, -56.00....]

and ybins array of range values [-9999.0, 0.0, 0.0, 500.0 99999.0]

the result gives [1,3,1..]

if value of 0.0 used in xfloatarray returns value of 3 ie value of 2 not returned.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -