如何将xarray数据集转换为纯二进制文件?

时间:2018-08-14 14:42:30

标签: python numpy python-xarray

我有以下代码:

import xarray, struct
ds = xarray.open_dataset("dataset.nc")
with open("filename.bin", "wb") as file_out:
    rows, cols = ds["datasetname"].shape
    for x in range(cols):
        for y in range(rows):
          file_out.write(struct.pack("i", ds["datasetname"][y, x]))

是否有更快/更好或更numpy / xarray-ish的方式来做到这一点?

0 个答案:

没有答案