samedi 7 avril 2018

Variable gets expanded in a loop with condition, how to "reset" when certain condition met?

I have a loop that scans through each data point and checks for a certain condition:

for i in range(0, 10):
    if x == False:     #1
       if a.loc[[i]] > b.loc[[i]]: #2
          value = "yes"
          test = 1 / y.loc[[i]]
       ...

    if value == "yes":
          test_2 = test * z.loc[[i]]
          x = True

    elif x == True: #3
      ...
          test_3 = test - test_2 * e.loc[[i]] #4
          x = False

and so on.

The variable at questions are here test and resulting from that test_2 and test_3. These should just be 1x1 variable, however, the condition #1 and #2 are met throughout the loop causing that test gets expanded to 1xN. such that test_3 below does not work anymore.

How can I make: the loop or the conditions to "reset" the variable test, as soon as my conditions #3 and #4 are met such that when the loops starts at 1 again, I will get a 1x1 variable test? thank you.

Aucun commentaire:

Enregistrer un commentaire