微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在for循环的每次迭代中保存变量

如何解决如何在for循环的每次迭代中保存变量

我编写了一个 for 循环来计算我的 NetCDF 文件的样本滚动平均值(73、10000、10000),它计算了 25 个维度为(73、2000、2000)的字幕的滚动平均值,我想在每次迭代时保存此 vh_sub_roll 以实现最终更正的 NetCDF 文件,该文件也是 (73,10000,10000),但我不知道该怎么做。有人可以帮助解决这个问题。

 vh = xarray.open_dataset('D:/kfakheri_data/thesis/Netcdf_files/all/ultimate_netcdf_VH.nc')
 maxr = 5
 # subtile numbers help to check individual parts of the array,if necessary. 1=upper right,25=lower left corner
 subtile = 1
 for rx in range(maxr):
      for ry in range(maxr):
         x1 = rx*2000
         x2 = rx*2000+2000-1
         y1 = ry*2000+2000-1
         y2 = ry*2000
         print(x1,x2,y2,y1)
         # slice entire tile into 2000x2000 pixels
         vh_sub = vh.sel(x=slice(x1,x2),y=slice(y1,y2))
         # apply rolling average: average over 5 timestamps (centered around the timestamp of 
         interest),if less than
      
         vh_sub_roll = vh_sub['VH_gaussian'].rolling(dim={'time': 5},min_periods=2,center=True).mean()
         subtile += 1

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。