Expand dimensions xarray

前端 未结 2 2038
青春惊慌失措
青春惊慌失措 2021-01-19 05:07

Is there an existing method or approach to expand the dimensions (and coordinates) of an xarray.DataArray object?

I would like to obtain something simil

2条回答
  •  长发绾君心
    2021-01-19 05:55

    In xarray v0.10.0, I use a combination of assign_coords() and expand_dims() to add a new dimension and coordinate variable.

    For example:

    import xarray as xr
    import numpy as np
    data = xr.DataArray([1, 2, 3], dims='x', coords={'x': [10, 20, 30]})
    data_newcoord = data.assign_coords(y='coord_value')
    data_expanded = data_newcoord.expand_dims('y')
    print(data_expanded)
    # 
    # array([[1, 2, 3]])
    # Coordinates:
    #   * x        (x) int64 10 20 30
    #   * y        (y) 

提交回复
热议问题