我有一个从netCDF文件中导入的numpy数组,形状为(930, 360, 720),其中按时间、纬度和经度排序。
对于每个930个时间戳中的每个纬度/经度对,我需要计算值满足或超过阈值"x"(例如0.2或0.5等)的次数,并最终计算超过阈值的百分比,然后输出结果以便稍后绘制。
我尝试了许多方法,但这是我最近的尝试:
对于每个930个时间戳中的每个纬度/经度对,我需要计算值满足或超过阈值"x"(例如0.2或0.5等)的次数,并最终计算超过阈值的百分比,然后输出结果以便稍后绘制。
我尝试了许多方法,但这是我最近的尝试:
lat_length = len(lats)
#where lats has been defined earlier when unpacked from the netCDF dataset
lon_length = len(lons)
#just as lats; also these were defined before using np.meshgrid(lons, lats)
for i in range(0, lat_length):
for j in range(0, lon_length):
if ice[:,i,j] >= x:
#code to count number of occurrences here
#code to calculate percentage here
percent_ice[i,j] += count / len(time) #calculation
#then go on to plot percent_ice
希望这有意义!非常感谢任何帮助。我是自学的Python,所以可能会错过一些简单的东西。
这是否是使用any()函数的时候?最有效的方法是计算超过阈值的次数,然后计算百分比是什么?