xarray.NamedArray.expand_dims

xarray.NamedArray.expand_dims#

NamedArray.expand_dims(dim=Default.token)[source]#

Expand the dimensions of the NamedArray.

This method adds new dimensions to the object. The new dimensions are added at the beginning of the array.

Parameters

dim (Hashable, optional) – Dimension name to expand the array to. This dimension will be added at the beginning of the array.

Returns

NamedArray – A new NamedArray with expanded dimensions.

Examples

>>> data = np.asarray([[1.0, 2.0], [3.0, 4.0]])
>>> array = xr.NamedArray(("x", "y"), data)

# expand dimensions by specifying a new dimension name >>> expanded = array.expand_dims(dim=”z”) >>> expanded.dims (‘z’, ‘x’, ‘y’)