Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python初学者-在预定义的时间间隔内求和值_Python - Fatal编程技术网

Python初学者-在预定义的时间间隔内求和值

Python初学者-在预定义的时间间隔内求和值,python,Python,我有一个每小时雨量测量系列,每小时一个寄存器 我需要一个每天累积雨水的输出 我正在尝试下面的代码。第一天还可以,但第二天就不行了 数据=[0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0。 0. 0. 0. 0. 0. 0.2 14. 0. 0. 0. 0. 0. 0. 0. 0.2 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.6 0. 0. 0. 0. 0. 0.

我有一个每小时雨量测量系列,每小时一个寄存器

我需要一个每天累积雨水的输出

我正在尝试下面的代码。第一天还可以,但第二天就不行了

数据=[0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0。 0. 0. 0. 0. 0. 0.2 14. 0. 0. 0. 0. 0. 0. 0. 0.2 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.6 0. 0. 0. 0. 0. 0.2 0. 0. 0. 0. 0.6 0.2 4.2 0. 0. 0. 0.2 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0。]

b=24天窗口,24次测量,每小时一次

x=np.arange(06133,1,int)

日=np.零((6132,1))

对于x中的i:

if i < b:
    day[i] = data[i]

else:
    cum_day = np.sum(day)
如果i

打印(cum_day)

使用索引来过滤值,因为您已经有一个NumPy数组
x=b]
给出大于或等于
b
的值,然后简单求和。如果这不是你想要的,请解释你所说的24的间隔是什么意思。提供一个示例输入和输出

n = 10
b = n-1
x=np.arange(0,6133,1,int)

day = x[x<b]
cum_day = np.sum(x[x>=b])
print (cum_day)

使用索引来筛选值,因为您已经有一个NumPy数组
x=b]
给出大于或等于
b
的值,然后简单求和。如果这不是你想要的,请解释你所说的24的间隔是什么意思。提供一个示例输入和输出

n = 10
b = n-1
x=np.arange(0,6133,1,int)

day = x[x<b]
cum_day = np.sum(x[x>=b])
print (cum_day)

如果我没弄错你的问题,你只需要一个小屁股

您有一个长度为6132的数组。长度不能被24整除

所以我给你的数据加上零,使你的数据正好是256天的数据

data = [...] # 6132 hour datas in this array.
length = len(data) # it might be 6132
total_number_of_days = round(length/24 + 0.5) # number of days of your data
numpydata = np.array(data) # make a numpy array
numpydata = np.append(numpydata, [0]*(total_number_of_days*24-6132)) # append missing hours
datas_per_days = np.split(numpydata,total_number_of_days) # split array by number of days. (length of each row must be 24)
accumulated_rain_per_day = np.sum(datas_per_days,axis=1) # calculate rain per day...
print (accumulated_rain_per_day)
此代码将为您提供每天的降雨数据

每天累积降雨量[0]#第一天

每天累积降雨量[1]#第二天

每天的累积降雨量[2]#第三天


…如果我没弄错你的问题,你只需要一个小屁股

您有一个长度为6132的数组。长度不能被24整除

所以我给你的数据加上零,使你的数据正好是256天的数据

data = [...] # 6132 hour datas in this array.
length = len(data) # it might be 6132
total_number_of_days = round(length/24 + 0.5) # number of days of your data
numpydata = np.array(data) # make a numpy array
numpydata = np.append(numpydata, [0]*(total_number_of_days*24-6132)) # append missing hours
datas_per_days = np.split(numpydata,total_number_of_days) # split array by number of days. (length of each row must be 24)
accumulated_rain_per_day = np.sum(datas_per_days,axis=1) # calculate rain per day...
print (accumulated_rain_per_day)
此代码将为您提供每天的降雨数据

每天累积降雨量[0]#第一天

每天累积降雨量[1]#第二天

每天的累积降雨量[2]#第三天


……我认为,如果您能提供更多关于您试图实现的目标的背景信息,这将是非常有帮助的——如果我们了解您试图实现的目标,我们可能会建议一个更合适的解决方案。您能填写代码中设置
n
值的部分吗?输入是一个小时雨量测量序列,我有大约256天的6132条记录…我需要一个每天累积的降雨输出,每24小时累积的降雨(24个日志)-我认为如果您能提供更多关于您尝试完成的内容的上下文,这将是很有帮助的-如果我们了解您正在尝试做什么,我们可能会建议一个更合适的解决方案。您能填写代码中设置
n
值的部分吗?输入是一个小时雨量测量序列,其中我在大约256天内有6132条记录……我需要一个输出,其中包括每天累积的雨量、每24小时累积的雨量(24个日志)–Hi@Bazingaa,实际上我有一个降雨系列,我有每小时的测量,我想定义一天中累积的降雨,因为24是我的“窗户”。。现在我有了下面的代码,但它只适用于第一天#数据来自上面代码b=24#day窗口中加载的文件,24次测量,每小时一次x=np.arange(06133,1,int)day=np.zeros((6132,1)),如果I