xarray.DataArray.expand_dims

DataArray.expand_dims(dim=None, axis=None, **dim_kwargs)[source]

Return a new object with an additional axis (or axes) inserted at the corresponding position in the array shape. The new object is a view into the underlying array, not a copy.

If dim is already a scalar coordinate, it will be promoted to a 1D coordinate consisting of a single value.

Parameters
  • dim (hashable, sequence of hashable, dict, or None, optional) – Dimensions to include on the new variable. If provided as str or sequence of str, then dimensions are inserted with length 1. If provided as a dict, then the keys are the new dimensions and the values are either integers (giving the length of the new dimensions) or sequence/ndarray (giving the coordinates of the new dimensions).

  • axis (int, list of int or tuple of int, or None, default: None) – Axis position(s) where new axis is to be inserted (position(s) on the result array). If a list (or tuple) of integers is passed, multiple axes are inserted. In this case, dim arguments should be same length list. If axis=None is passed, all the axes will be inserted to the start of the result array.

  • **dim_kwargs (int or sequence or ndarray) – The keywords are arbitrary dimensions being inserted and the values are either the lengths of the new dims (if int is given), or their coordinates. Note, this is an alternative to passing a dict to the dim kwarg and will only be used if dim is None.

Returns

expanded (same type as caller) – This object, but with an additional dimension(s).