Question: Suppose I have a 1D array sorted in descending order, like:

`arr = np.array([10, 10, 8, 5, 4, 4, 3, 2, 2, 2])`

I want the index value, where the summation of this array starting from 0 to that index is greater than or equal to a specified target value. For example, let the target value be 40:

> 
> index=0 (0) => sum=10 (10)
> 
> 
> index=1 (0,1) => sum=20 (10+10)
> 
> 
> index=2 (0,1,2) => sum=28 (10+10+8)
> 
> 
> index=3 (0,1,2,3) => sum=33 (10+10+8+5)
> 
> 
> index=4 (0,1,2,3,4) => sum=37 (10+10+8+5+4)
> 
> 
> index=5 (0,1,2,3,4,5) => sum=41 (10+10+8+5+4+4)
> 
> 
> 

and finally I want to get the index value 5, since the sum 41 is greater than the target value 40. How can I do this in most Pythonic and appropriate way, so it can work with large numbers and large sized arrays.

Answer: 
Because the list is empty. That's why there are no elements thus no range
I think a bit more explanation is in order. You are thinking that the "2" parameter in the List constructor creates a list of size 2. It does not. It creates an empty list with a capacity of 2.
What that means effectively is that it pre-allocates enough space for two elements in the list so that as you add more and more elements it doesn't have to create add new space. However, the list is still empty, it just has some unused slots.

The way this works is that the list has a certain capacity at the start, in your case two so two "slots" are allocated for the elements, but the list is still empty. You add an element and it uses the first slot, you add another element and it takes the next slot, you add a third element, now it is out of slots, so it allocates more memory (4 slots for example) copies over the previous two into the first two slots of the new block, and now you have a capacity of 4 but a list of length 2.

Many years ago I had a problem with a production system that took forever to start up (though this was in C++.) In the loading phase we were loading stuff from a database into a memory list. It contained about 100,000 items. However the capacity was just 10. So it filled the first ten, when they were filled, it allocated 20 slots and copied over the first ten and released that memoer (the algorithm was that it doubled the capacity when it ran out), then 40, 80 and so forth. You can see that it CONSTANTLY was allocating slots and copying the same memory bytes over and over and over again in an exponential fashion.

We set the capacity correctly at the beginning and it instantly worked hugely faster.

So when you are making a really big list which you are adding to piecemeal, it often is a good idea to set the capacity at the beginning if you can. (FWIW, in C++ this is not only slow but causes horrible memory fragmentation, which is much less of an issue in a garbage collected language like C#.)