title: How many elements of numpy array in specified number range
body: <p>For a list of <strong>sorted</strong> numpy arrays of <strong>unequal</strong> lengths (say <code>M0</code>, <code>M1</code>, <code>M2</code>) I want to find how many elements of each of these arrays is inside number ranges which are given by a adjoining pairs of an array (say <code>zbin</code>. <code>zbin</code> is <strong>not sorted</strong> and the said number ranges are like the following <code>[z[0], z[1]]</code>, <code>[z[2], z[3]]</code>, <code>[z[4], z[5]]</code> and so on. <code>zbin</code> always has an even number of elements. ) The <strong>unsorted nature</strong> of <code>zbin</code> and the consideration of <strong>adjoining pairs</strong> for in <code>zbin</code> for finding the number ranges makes this question different from the one asked here <a href="https://stackoverflow.com/questions/50362479/number-of-elements-of-numpy-arrays-inside-specific-bins">Number of elements of numpy arrays inside specific bins</a> . In the said link, <code>zarr</code> was <strong>sorted</strong> and <em>adjoining elements</em> gave number ranges (here <em>adjoining pairs</em> give number ranges).</p>
  
  <p>This is what I am doing presently:</p>
  
  <pre><code>""" Function to do search query """
  def search(numrange, lst):
      arr = np.zeros(len(lst))        
      for i in range(len(lst)):
          probe = lst[i]
          count = 0
          for j in range(len(probe)):
              if (probe[j]&gt;numrange[1]): break
              if (probe[j]&gt;=numrange[0]) and (probe[j]&lt;=numrange[1]): count = count + 1   
  
          arr[i] = count
      return arr
  
  
  """ Some example of sorted one-dimensional arrays of unequal lengths """
  M0 = np.array([5.1, 5.4, 6.4, 6.8, 7.9])
  M1 = np.array([5.2, 5.7, 8.8, 8.9, 9.1, 9.2])
  M2 = np.array([6.1, 6.2, 6.5, 7.2])
  
  """ Implementation and output """
  lst = [M0, M1, M2]
  zbin = np.array([5.0, 5.2, 5.1, 5.3, 5.2, 5.4])
  
  zarr = np.zeros( (len(zbin)/2, len(lst)) )
  for i in np.arange(0, len(zbin)/2, 1):
      indx = i*2
      print indx
      numrange = [zbin[indx], zbin[indx+1]]
      zarr[i,:] = search(numrange, lst)
  
  print zarr  
  </code></pre>
  
  <p>The <strong>output</strong> is:</p>
  
  <pre><code>[[ 1.  1.  0.]
   [ 1.  1.  0.]
   [ 1.  1.  0.]]
  </code></pre>
  
  <p>Here, the first row of <code>zarr</code> (<code>[1,1,0]</code> shows that <code>M0</code> has <strong>1</strong> element in the considered number range <code>[5.0, 5.2]</code>, <code>M1</code> has <strong>1</strong> element and <code>M2</code> has <strong>0</strong> elements. The second and the third rows show results for the subsequent number ranges, <em>i.e.</em> <code>[5.1, 5.3]</code> and <code>[5.2, 5.4]</code>.)</p>
  
  <p>I want to know what is the fastest way to achieve this desired functionality (<code>zarr</code>). In my actual task, I will be dealing with <code>zbin</code> of much bigger size, and many more arrays (<code>M</code>). I will very much appreciate any help.</p>