赞
踩
- import numpy as np
- import netCDF4 as nc
-
- nc_file = 'F:\Deepmind\exampleInputs\stats\stats_diffs_stddev_by_level.nc'
-
- with nc.Dataset(nc_file, 'r') as data:
- # 查看文件中的所有变量名称
- variable_names = data.variables.keys()
- # print('Variable Names:', variable_names)
-
- # 访问其中一个变量
- your_variable = data['temperature'] # 将 'your_variable_name' 替换为实际变量的名称
-
- # 打印变量内容
- print('Your Variable:', your_variable[:]) # 可以使用切片来获取变量的值
-
- # 查看变量的属性
- variable_attributes = your_variable.ncattrs()
- print('Variable Attributes:', variable_attributes)
- for attribute_name in variable_attributes:
- print(f'{attribute_name}: {your_variable.getncattr(attribute_name)}')
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。