将Python词典保存到netCDF4文件 [英] Saving Python dictionary to netCDF4 file

查看:71
本文介绍了将Python词典保存到netCDF4文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习对netCDF4(和一般的netCDF4)使用Python模块.使用HDF5文件格式,有一种自然的方法可以将Python词典转换为HDF5数据结构-使用组的属性:

I am learning to use Python module for netCDF4 (and netCDF4 in general). Using HDF5 file format, there is a natural way to translate Python dictionaries to HDF5 data structure - using group's attributes:

parameters = {'a':1.0, 'b':2.0, 'c':3.0}
f = h5py.File("test.hdf5",'w')
hdf_parms = f.create_group("parameters")
for k,v in parameters.items():
        hdf_parms.attrs[k]=v

netCDF4的聪明方法是什么?

What is the smart netCDF4 way to do this?

推荐答案

类似的东西

parameters = {'a':1.0, 'b':2.0, 'c':3.0}
f = netCDF4.Dataset('test.nc', 'w')
parms = f.createGroup('parameters')
for k,v in parameters.items():
    setattr(parms, k, v)

这篇关于将Python词典保存到netCDF4文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆