用python读取一个nc文件中的指定的一个变量并输出他的维度
下面是一个使用Python读取.nc文件中指定变量并输出其维度的示例代码:
import netCDF4 as nc
# 打开.nc文件
dataset = nc.Dataset('your_file.nc')
# 指定要读取的变量名称
variable_name = 'your_variable'
# 获取变量对象
variable = dataset.variables[variable_name]
# 输出变量的维度
print(variable.dimensions)
# 关闭文件
dataset.close()
请将"your_file.nc"替换为你的.nc文件的路径,将"your_variable"替换为你要读取的变量的名称。运行代码后,将会输出该变量的维度信息。
原文地址: https://www.cveoy.top/t/topic/hFrA 著作权归作者所有。请勿转载和采集!