xarray.DataArray.expand_dims

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

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) – 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). WARNING for python 3.5, if dim is dict-like, then it must be an OrderedDict. This is to ensure that the order in which the dims are given is maintained.

  • axis (integer, list (or tuple) of integers, or 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/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. WARNING for python 3.5 dim_kwargs is not available.

Returns

expanded – This object, but with an additional dimension(s).

Return type

same type as caller