I have a 2D array in the following form:
[[X1, X2, ..., XN]
[Y1, Y2, ..., YN]]
For each Xi greater than lower_limit_X and less than upper_limit_X, I would like to get the number of Yi‘s that are greater than lower_limit_Y and less than upper_limit_Y.
I hope there is an efficient way of doing this in Numpy apart from indexing one by one.
EDIT:
So I have a 2xN array. The first row has ordered values of N X’s and second row has ordered values of N Y’s. What I would like to get is:
-
get a the
lowest_indexandhighest_indexindex of X, that have a value that is greater thanlower_limit_Xand less thanupper_limit_X -
then slice the Y array (just one array) in the index range [
lowest_index,highest_index] -
count the number of elements in my slice, having Yi
's that are greater thanlower_limit_Yand less thanupper_limit_Y`.
Here are two ways you could do this, the more strait forward way is probably,
If your array is very large and both x and y are sorted you could use
searchsortedinstead,