I have the following Python code that I want to express mathematically.
W = 0
for i in range(5):
if (A > i_1) and ( (A < i_2) or (A < i_3) ):
W = W + 1
This is a generic problem that I am trying to achieve; looping over some values and checking some condition. If the condition is satisfied, I want to add 1 to the counter (W in this case); otherwise, skip to the next value. How can I express this using a mathematical formula?
To be more specific:
for row in DF1.iterrows():
pTime = row['A1_time']
W = 0
for row2 in DF1.iterrows():
a1 = row2['A1_time']
a2 = row2['A2_time']
a3 = row2['A3_time']
if (pTime > a1) and ( (pTime < a2) or (pTime < a3) ):
W = W + 1
for i in range (5)
represents looping over some values. I will correct the code to be more clear. – O.Mohsen Jul 26 '20 at 05:58i_1, i_2, i_3, A
depend oni
? Andsum(1 for i in range(5) if (A > i_1) and ( (A < i_2) or (A < i_3) ))
could be more pythonic. – Alexey Burdin Jul 26 '20 at 06:01