Python初学者在预定义的

2024-06-16 10:04:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个每小时一次的雨量测量系列,每小时一次

我需要一个每天累积雨水的产量

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

数据=[0。0000000000000 000000.2 14. 0000000 0.2 0. 000000000.6 0. 00 000.2 0. 0000.6 0.2 4.2 0. 000.2 00000000000000 0]你知道吗

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

十=np.arange公司(06133,1内景)

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

对于x中的i:

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

else:
    cum_day = np.sum(day)

打印(累计日)


Tags: 数据代码dataifnp公司else产量
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]#第三天。。。你知道吗

。。。。。。你知道吗

使用索引来筛选值,因为您已经有了NumPy数组。x<b给出x中的值低于b的索引。您将这些索引作为参数传递给x[],它只提供那些小于b的值的子数组。x[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)

输出

18803742

相关问题 更多 >