小编Hap*_*ier的帖子

如何更改 xarray.Dataset 维度的顺序?

我正在创建一个 xarray 数据集,如下所示:

import numpy as np
import xarray as xr

x_example = np.random.rand(1488,)
y_example = np.random.rand(1331,)
time_example = np.random.rand(120,)
rainfall_example = np.random.rand(120, 1331, 1488)

rainfall_dataset = xr.Dataset(
    data_vars=dict(
        rainfall_depth=(['time', 'y', 'x'], rainfall_example),
    ),
    coords=dict(
        time=(['time'], time_example),
        x=(['x'], x_example),
        y=(['y'], y_example)
    )
)
Run Code Online (Sandbox Code Playgroud)

结果是这样的

在此输入图像描述

而我跑步时的尺寸rainfall_example.dims是这样的Frozen({'time': 120, 'y': 1331, 'x': 1488})(这也可以从上面的结果中看出)。我知道xarray.Dataset.dims不能根据这里修改

我的问题是:我们如何才能将这些维度的顺序更改为这样的维度Frozen({'time': 120, 'x': 1488, 'y': 1331})而不更改其他任何内容(一切都将相同,只是维度的顺序发生了变化)?

dataset dimensions python-xarray

7
推荐指数
1
解决办法
6526
查看次数

标签 统计

dataset ×1

dimensions ×1

python-xarray ×1