mercredi 3 juin 2015

Why is this for loop taking an extremly long time to finish

I have the following for loop that is part of a larger code. So far it has been running over night. The input data is a file of three columns and roughly 5 million rows. The code is not carrying out any complex computations so I am at a loss as to why this is taking so long to complete. I am running cProfile at the moment to see if I can find any bottle necks , but wanted to ask if there was anything simple that I have missed?

 TID = []            
 M   = []           
 R   = []           

 ID = np.array(TID,dtype=float)   
 MASS = np.array(M, dtype=float)       #Converts lists to NumPy arrays
 RED = np.array(R, dtype=float)

 def formation_def():

 count = 100000000
 l =len(TID)
 for i in range(l):
   if ID[i] == count:
     for j in range(i,l):   
       if MASS[j] > (0.02)*MASS[i]/2:
          continue
       else:
         filesave(MASS[j-1],RED[j-1])  
         count += 100000000    
         break
   else:
       count +=100000000  

Aucun commentaire:

Enregistrer un commentaire