Combining data¶
- For combining datasets or data arrays along a dimension, see concatenate.
- For combining datasets with different variables, see merge.
- For combining datasets or data arrays with different indexes or missing values, see combine.
Concatenate¶
To combine arrays along existing or new dimension into a larger array, you
can use concat()
. concat
takes an iterable of DataArray
or Dataset
objects, as well as a dimension name, and concatenates along
that dimension:
In [1]: arr = xr.DataArray(np.random.randn(2, 3),
...: [('x', ['a', 'b']), ('y', [10, 20, 30])])
...:
In [2]: arr[:, :1]
Out[2]:
<xarray.DataArray (x: 2, y: 1)>
array([[ 0.469112],
[-1.135632]])
Coordinates:
* x (x) <U1 'a' 'b'
* y (y) int64 10
# this resembles how you would use np.concatenate
In [3]: xr.concat([arr[:, :1], arr[:, 1:]], dim='y')