add dimension to an xarray DataArray

。_饼干妹妹 提交于 2019-12-04 04:40:24

If DA is your data array with length DimLen, you can now use:

DA.expand_dim({'NewDim':DimLen})

You've done a pretty thorough analysis of the current options, and indeed none of these are very clean.

This would certainly be useful functionality to write for xarray, but nobody has gotten around to implementing it yet. Maybe you would be interested in helping out?

See this GitHub issue for some API proposals: https://github.com/pydata/xarray/issues/170

Because of the way that math is applied over new dimensions I like to multiply in order to add new dimensions.

identityb = xr.DataArray(np.ones_like(b_coords), coords=[('b', b_coords)])
y = x * identityb
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!