這是驅動我香蕉:) 我想根據月份從列表中總結值,我嘗試了一些東西,但非常需要指導。Python:如果循環嵌套
我想: 對於第1個月 - 12
迭代讀PlanWeek(4)從列表(EC_PlanData)和SUM
然後計算基於累加值平滑avergae值。
這裏是我的代碼:
G_counter = 1
j = i
m = 1
Plantotal = 0
PlanMonth = 0
DFD = []
EC_PlanData = [500,500.... etc] # 52 values
PlanWeek = range(j,j+3)
Month = range(m,13,1)
## Define Variables
ym, xh, xm, N1, Z1, N2, Z2 = 0,0,0,0,0,0,0
for month in Month: # for each month 1 - 13
for i,e in enumerate(list_1): # read through list
PlanMonth = PlanMonth + i+3 # sum 4 weekly values
DFD.append(PlanMonth) # append sum value to DFD list
if i == 1: # if G_counter = 1, which it always is
IFX.append(PlanMonth) # also append to IFX list
Plantotal= Plantotal+PlanMonth # calculations here on are
for i,e in enumerate(DFD): # evaluated after appending above
y = e
ym = Plantotal/m # These are calculating a smoothing average
xh = xh + m
xm = xh/m
N1 = (m-xm) * (y-ym)
Z1 = (m-xm) * (m-xm)
N2 = N2 + N1
Z2 = Z2 + Z1
if Z2 == 0: # Decision on FC value
FC = 0 # This or
else:
FC = ym -(N2/Z2)*xm + (N2/Z2)*(m+1) # This
J +=4 # Advances on 4 time periods
M +=1 # Advances on 1 Month
PlanMonth = 0 # Resets PlanMonth variable
PlanMonth最初來自哪裏?我希望你在列表中沒有真正寫52次52次,list_2和list_3在哪裏?究竟是什麼問題? PlanWeek是什麼? – 2012-08-14 09:03:55
目前尚不清楚你想要達到的目標。建議用僞代碼描述問題 – 2012-08-14 09:05:13
你會得到什麼? – joaquin 2012-08-14 09:05:14