I am using python 3.2.0 and numpy. I would like to check if one of the arrays is in between two other specified arrays. I would like it if you suggest a function or few of them together. Any help is appreciated , as it is a school project and I need to submit it quickly.
How to see if a given array is between two arrays
368 views Asked by Sam At
2
There are 2 answers
0
On
If you had 3 arrays,
#lower bound
In[1]: small = np.zeros((3,3))
#Array we are testing
In[2]: test = np.ones((3,3))
#Upper bound
In[3]: large = np.ones((3,3))*2
then you could do a logical_and and test the entire array with the Boolean sum against the size
In[4]: np.logical_and(small<=testm,testm<=large).sum() == l.size
out[4]: True
If you mean how the last item of arr1 is less than all items of input_arr, and the first item of arr2 is greater than all those in input_arr, you can do this, with "biggest" of arr1 and "smallest" of arr2:
Alternatively, you could change the < and/or the > to <= or >= if you allow equals to (so [1,3,4],[4,6,8],[8,17,18] is True)
This assumes that the lists are consecutive. If they're not, you'll have to loop through arr1 to find the largest number and arr2 to find the smallest first.
Use this as a skeleton guide, don't just copy and paste. If you don't understand it and therefore can't construct your own version, you probably need to do some sort of online course (eg. Codecademy). In the mean time, copy the 2nd bit first if you need it, then the first.