Python 如何在xarray.DataArray中为另一维度的不同坐标获取不同数量的维度坐标?
我想要一个xarray.DataArray来存储一些结果。初始化的结果DataArray如下所示:Python 如何在xarray.DataArray中为另一维度的不同坐标获取不同数量的维度坐标?,python,python-xarray,Python,Python Xarray,我想要一个xarray.DataArray来存储一些结果。初始化的结果DataArray如下所示: import xarray as xr import numpy as np time_steps = np.arange(5) region_ids = ['region_'+str(i) for i in np.arange(5)] cluster_ids = ['cluster_'+str(i) for i in np.arange(5)] #5 being max no. of clu
import xarray as xr
import numpy as np
time_steps = np.arange(5)
region_ids = ['region_'+str(i) for i in np.arange(5)]
cluster_ids = ['cluster_'+str(i) for i in np.arange(5)] #5 being max no. of clusters
data = np.zeros((len(time_steps), len(region_ids), len(cluster_ids)))
data.fill(np.nan)
result = xr.DataArray(data, [('time', time_steps),
('region_ids', region_ids),
('cluster_ids', cluster_ids)])
现在假设我得到第一个区域的结果('region\u 0'
)。根据该算法,3个簇就足够了。所以我的结果看起来像:
result_region = np.random.rand(5,3)
当我尝试使用下面的命令保存结果时,我得到一个错误:
result.loc[:,'region_0',:] = result_region
ValueError: could not broadcast input array from shape (5,3) into shape (5,5)
如何删除额外的簇坐标并保存结果?
对于不同的区域坐标,是否可能有不同数量的簇坐标
提前谢谢