title: Formating numpy arrays to find the sum betyween 2 values Python
body: <p>I am trying to modify the values of the values down below to the expected values. The function down below is meant to sum out all the values between 2 consecutive elements of <code>limits</code>. none of the values are between <code>0 and 2</code> within <code>Numbers</code> so the resultant is 0. However the values between <code>2 and 5</code> are <code>3,4</code> within <code>Numbers</code> so the resultant is <code>3+4=7</code>. The function has been gotten from issue: <a href="https://stackoverflow.com/questions/66593076/working-with-2-arrays-with-different-lengths-numpy-python">issue</a>.</p>
  <pre><code>def formating(a, b):
      
      # Formating goes here
      x = np.sort(b);
      # digitize
      l = np.digitize(a, x)
      # output:
      result = np.bincount(l, weights=a)
      return result
  
  Numbers = np.array([3, 4, 5, 7, 8, 10,20])
  limit1 = np.array([0, 2 , 5, 12, 15])
  limit2 = np.array([0, 2 , 5, 12])
  limit3 = np.array([0, 2 , 5, 12, 15, 22])
  
  result1= formating(Numbers, limit1)
  result2= formating(Numbers, limit2)
  result3= formating(Numbers, limit3)
  </code></pre>
  <p>Current output</p>
  <pre><code>result1:  [ 0.  0.  7. 30.  0. 20.] 
  result2:  [ 0.  0.  7. 30. 20.] 
  result3:  [ 0.  0.  7. 30.  0. 20.]
  </code></pre>
  <p>Wanted Output:</p>
  <pre><code>result1:  [ 0.  7. 30.  0.] 
  result2:  [ 0.  7. 30. ] 
  result3:  [ 0.  7. 30.  0. 20.]
  </code></pre>