0

In my code I have the following line

56 if(0 <= m and m <= 1000): ---> 57 simulacion[m][p] = 1

Non the less, I keep having the error

index -1313 is out of bounds for axis 0 with size 1000

Clearly m can not be -1313 due to the conditional statement. Does somebody know what is happening? I am using Python 2.7. If extra information is needed, let me know. It is for a traffic simulation project.

Ivan Burbano
  • 239
  • 1
  • 3
  • 11

1 Answers1

0

It sounds like you will want to debug what the arguments are when it breaks. put in a try except block.

try:
    simulacion[m][p]=1
except IndexError:  
    print('simulation broke again with an index error')
    print('m is: '+str(m))
    print('p is: '+str(p))
    #possibly more info needed to diagnose the error here

Make sure you are keeping limits on 'p' as well as 'm' to make sure m*p stays within the limits of your iterable.

Back2Basics
  • 7,406
  • 2
  • 32
  • 45