cmomy.concat#
- cmomy.concat(arrays, *, axis=MISSING, dim=MISSING, **kwargs)[source]#
Concatenate moments objects.
- Parameters:
arrays (
Iterable
ofndarray
orDataArray
orCentralMomentsArray
orCentralMomentsData
) – Central moments objects to combine.axis (
int
, optional) – Axis to concatenate along. If specify axis forDataArray
orCentralMomentsData
input objects with outdim
, then determinedim
fromdim = first.dims[axis]
wherefirst
is the first item inarrays
.dim (
str
, optional) – Dimension to concatenate along (used forDataArray
andCentralMomentsData
objects only)**kwargs (
Any
) – Extra arguments tonumpy.concatenate()
orxarray.concat()
.
- Returns:
output (
ndarray
orDataArray
orCentralMomentsArray
orCentralMomentsData
) – Concatenated object. Type is the same as the elements ofarrays
.
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
andCentralMomentsData
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