我有以下代码:
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的方式来做到这一点?