Expand dimensions xarray

前端 未结 2 1998
青春惊慌失措
青春惊慌失措 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:48

    I agree that some sort of method for doing this would be useful. It does not currently exist directly in xarray, but I would encourage you to file an issue on GitHub to discuss API for a new feature and/or make a pull request implementing it.

    The new xarray.broadcast function contains some related functionality that may suffice for this purposes:

    import xarray as xr
    import numpy as np
    data = xr.DataArray([1, 2, 3], dims='x')
    other = xr.DataArray(np.zeros(4), coords=[('y', list('abcd'))])
    data2, other2 = xr.broadcast(data, other)
    print(data2)
    # 
    # array([[1, 1, 1, 1],
    #       [2, 2, 2, 2],
    #       [3, 3, 3, 3]])
    # Coordinates:
    #   * x        (x) int64 0 1 2
    #   * y        (y) |S1 'a' 'b' 'c' 'd'
    

提交回复
热议问题