IndexError: index 10 is out of bounds for axis 0 with size 10
You try to index outside the range: Change to: And it works. You create t with length of M: So you can only access M elements in t. Python always starts indexing with zero. Therefore: will do M loops, while: will do M+1 loops.