我正在尝试创建一个方法,我有一个数组的风和需求平均通过一天在15分钟的间隔为1年。我想把这变成365天的每日平均值。以下是我目前掌握的情况:
dailyAvg = [] # this creates the initial empty array for method below
def createDailyAvg(p): # The method
i = 0
while i < 35140: # I have 35140 data points in my array
dailyAvg.append(np.mean(p[i:i+95])) #Creates the avg of the 96, 15 minute avg
i += 95
return dailyAvg
dailyAvgWind = createDailyAvg(Wind) # Wind is the array of 15 minute avg's.
dailyAvgDemand = createDailyAvg(M) # M is the array of demand avg's
到目前为止,我可以做到这一点,如果我写两次,但这不是好的编程。我想弄清楚如何在两个数据集上使用这个方法。谢谢。你知道吗
您只需要将
dailyAvg
设置为函数的本地。这样,每次函数执行时,它都会被初始化为一个空列表(我打赌问题是函数的结果不断增长,不断增长,添加新的平均值,但不会删除以前的平均值)另外,我在两个位置将95替换为96,因为切片的结尾不包括指定的结尾。你知道吗
相关问题 更多 >
编程相关推荐