cmomy.concat

Contents

cmomy.concat#

cmomy.concat(arrays, *, axis=MISSING, dim=MISSING, **kwargs)[source]#

Concatenate moments objects.

Parameters:
Returns:

output (ndarray or DataArray or CentralMomentsArray or CentralMomentsData) – Concatenated object. Type is the same as the elements of arrays.

Examples

>>> import cmomy
>>> shape = (2, 1, 2)
>>> x = np.arange(np.prod(shape)).reshape(shape).astype(np.float64)
>>> y = -x
>>> out = concat((x, y), axis=1)
>>> out.shape
(2, 2, 2)
>>> out
array([[[ 0.,  1.],
        [-0., -1.]],

       [[ 2.,  3.],
        [-2., -3.]]])
>>> dx = xr.DataArray(x, dims=["a", "b", "mom"])
>>> dy = xr.DataArray(y, dims=["a", "b", "mom"])
>>> concat((dx, dy), dim="b")
<xarray.DataArray (a: 2, b: 2, mom: 2)> Size: 64B
array([[[ 0.,  1.],
        [-0., -1.]],

       [[ 2.,  3.],
        [-2., -3.]]])
Dimensions without coordinates: a, b, mom

For DataArray objects, you can specify a new dimension

>>> concat((dx, dy), dim="new")
<xarray.DataArray (new: 2, a: 2, b: 1, mom: 2)> Size: 64B
array([[[[ 0.,  1.]],

        [[ 2.,  3.]]],


       [[[-0., -1.]],

        [[-2., -3.]]]])
Dimensions without coordinates: new, a, b, mom

You can also concatenate CentralMomentsArray and CentralMomentsData objects

>>> cx = cmomy.CentralMomentsArray(x)
>>> cy = cmomy.CentralMomentsArray(y)
>>> concat((cx, cy), axis=1)
<CentralMomentsArray(mom_ndim=1)>
array([[[ 0.,  1.],
        [-0., -1.]],

       [[ 2.,  3.],
        [-2., -3.]]])
>>> dcx = cmomy.CentralMomentsData(dx)
>>> dcy = cmomy.CentralMomentsData(dy)
>>> concat((dcx, dcy), dim="new")
<CentralMomentsData(mom_ndim=1)>
<xarray.DataArray (new: 2, a: 2, b: 1, mom: 2)> Size: 64B
array([[[[ 0.,  1.]],

        [[ 2.,  3.]]],


       [[[-0., -1.]],

        [[-2., -3.]]]])
Dimensions without coordinates: new, a, b, mom