samedi 10 août 2019

How to speed up execution of for loop in Python?

I have coded a for loop, with conditional statement and updates made to a list variable at every iteration, which probably is making the process really slow. Is there a way to speed up this process and accomplish the same results as this code snippet performs?

fault_array =[] 
for i in x_range_original:
  for j in range(0,16):
    lower_threshold = min(df_log[:,j])
    upper_threshold = max(df_log[:,j])

    if((df_log[i,j] < lower_threshold) or (df_log[i,j] > upper_threshold)):
      print("Fault detected at timestep: ",df_records['Time'][i])
      fault_array.append(1)
    else:
      print("Normal operation at timestep: ",df_records['Time'][i])

      fault_array.append(0)

Aucun commentaire:

Enregistrer un commentaire