xarray.DataArray.swap_dims¶
-
DataArray.
swap_dims
(self, dims_dict: Mapping[Hashable, Hashable]) → 'DataArray'¶ Returns a new DataArray with swapped dimensions.
- Parameters
dims_dict (dict-like) – Dictionary whose keys are current dimension names and whose values are new names. Each value must already be a coordinate on this array.
- Returns
swapped – DataArray with swapped dimensions.
- Return type
Examples
>>> arr = xr.DataArray(data=[0, 1], dims="x", coords={"x": ["a", "b"], "y": ("x", [0, 1])}) >>> arr <xarray.DataArray (x: 2)> array([0, 1]) Coordinates: * x (x) <U1 'a' 'b' y (x) int64 0 1 >>> arr.swap_dims({"x": "y"}) <xarray.DataArray (y: 2)> array([0, 1]) Coordinates: x (y) <U1 'a' 'b' * y (y) int64 0 1
See also