1,数据格式很简单,有四周也就是28天的数据,每天有144个数据,共有4032个,如下:
11.028366381681027
11.127100875673675
10.892770602791097
8.6224245909897488
8.0099274624457563
8.1184195540896
8.0262697485121513
8.5141785771838925
······
用Sij表示一星期当中第j天第i个观测值,其中j=1,2,3,4,5,6,7;i=1,2,3,…,144;
现在想求出4032个Yij的值
我写了一个有些复杂的,但是感觉不太对,请大神们帮忙看看,感谢
from __future__ import pision
import matplotlib.pyplot as plt
with open('training_data.txt')as reader,open('weken4-4.txt','w')as writer:
sum1=[0 for x1 in range(0,144)]
sum2=[0 for x2 in range(0,144)]
sum3=[0 for x3 in range(0,144)]
sum4=[0 for x4 in range(0,144)]
data=[0 for y1 in range(0,4032)]
for index,line in enumerate(reader):
for i in range(0,144):
if index<1008:
if (index-i)%144==0:
sum1[i]=sum1[i]+float(line)
if 1008<=index<2016:
if (index-i)%144==0:
sum2[i]=sum2[i]+float(line)
if 2016<=index<3024:
if (index-i)%144==0:
sum3[i]=sum3[i]+float(line)
elif 3024<=index<4032:
if (index-i)%144==0:
sum4[i]=sum4[i]+float(line)
file = open('training_data.txt','r')
for j in range(0,4032):
line = file.readline()
a= line.split()
if j<1008:
data[j]=(float(a[0])-(sum1[j%144]/7))/(sum1[j%144]/7)
if 1008<=j<2016:
data[j]=(float(a[0])-(sum2[j%144]/7))/(sum2[j%144]/7)
if 2016<=j<3024:
data[j]=(float(a[0])-(sum3[j%144]/7))/(sum3[j%144]/7)
elif 3024<=j<4032:
data[j]=(float(a[0])-(sum4[j%144]/7))/(sum4[j%144]/7)
是求每周的每一点的平均偏离比例吧!关健是定义好数据结构,其他的都好办!