title: Fastest way to check which interval index a value is
body: <p>I have a vector like this:</p>
  
  <pre><code>intervals = [6, 7, 8, 9, 10, 11] #always regular
  </code></pre>
  
  <p>I want to check which interval index a value is. For example: the index of the interval where <code>8.5</code> is, is <code>3</code>.</p>
  
  <pre><code>#Interval : index
  6  -&gt; 7   : 1
  7  -&gt; 8   : 2
  8  -&gt; 9   : 3
  9  -&gt; 10  : 4
  10 -&gt; 11  : 5
  </code></pre>
  
  <p>So I made this code:</p>
  
  <pre><code>from numpy import *
  N = 8000
  data = random.random(N)
  step_number = 50
  max_value = max(data)
  min_value = min(data)
  step_length = (max_value - min_value)/step_number
  intervals = arange(min_value + step_length, max_value + step_length, step_length )
  for x in data:
      for index in range(len(intervals)):
          if x &lt; intervals[index]:
              print("That's the index", index)
              break
  </code></pre>
  
  <p>This code is working, but It's tooo slow, I think I'm wasting time in these loops. Is there a way to check this faster? Maybe using some numpy special function that check this for me...</p>