python - numpy.searchsorted in a multidimensional array -


i have got 3 dimensional array air pressure values in form:

[[[1000 1010]   [1005 990]]  [[950 960]  [955 940]]  [[900 910] [905 890]]] 

the structure represents pressure @ different levels, each element in 2-d ordered each layer.

i know @ level pressure 950 each 2d element, getting 2-d array index of level each element.

in 1-d array

a = [890, 940, 990] 

i use

a.searchsorted(950) 

and result 2, indicating 950 go @ 3rd position.

is there way array @ once, without having each 2-d element?

you can apply searchsorted function along axis of input array this:

numpy.apply_along_axis(lambda a: a.searchsorted(950), axis = 1, arr = air_pr) 

which should yield intended result if understand correctly.


Comments