一个简单的示例如下所示:
arr = xr.DataArray(np.random.rand(2,3,4), coords={'x': ['a', 'b'], 'y': ['c','d', 'e'], 'z': ['f', 'g', 'h', 'i']}, dims=('x', 'y', 'z'))
to_add = np.random.rand(3,4)
如何使用标签添加to_add
到坐标x
中? arr
a_plus
所以结果看起来像:
<xarray.DataArray (x: 3, y: 3, z: 4)>
array([[[0.753333, 0.585982, 0.271593, 0.017763],
[0.858164, 0.628703, 0.951855, 0.097232],
[0.372766, 0.006932, 0.848118, 0.06778 ]],
[[0.935869, 0.517625, 0.841972, 0.116477],
[0.161093, 0.449632, 0.640333, 0.578949],
[0.613066, 0.315713, 0.227409, 0.853698]],
[[0.405509, 0.194987, 0.662878, 0.105522],
[0.565623, 0.436369, 0.153299, 0.72756 ],
[0.589336, 0.957754, 0.645316, 0.319808]]])
Coordinates:
* y (y) |S1 'c' 'd' 'e'
* x (x) |S6 'a' 'b' 'a_plus'
* z (z) |S1 'f' 'g' 'h' 'i'