# xarray.DataArray.swap_dims

#### DataArray.swap_dims(dims_dict=None, \*\*dims_kwargs)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataarray.py#L2733-L2790)

Returns a new DataArray with swapped dimensions.

* **Parameters:**
  * **dims_dict** ([dict-like](https://docs.python.org/3/glossary.html#term-mapping)) – Dictionary whose keys are current dimension names and whose values
    are new names.
  * **\*\*dims_kwargs** (`{existing_dim: new_dim, ...}`, *optional*) – The keyword arguments form of `dims_dict`.
    One of dims_dict or dims_kwargs must be provided.
* **Returns:**
  **swapped** ([`DataArray`](xarray.DataArray.html.md#xarray.DataArray)) – DataArray with swapped dimensions.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('98933dc9-e9e8-4376-9c93-350f9318302e','f112a42d-eac2-4df0-a3db-60167e8c2baa','ee4b507f-7e53-434e-a439-82054f2296c4','../lite/tree/../notebooks/index.html?path=fee45bfa_82c7_4280_be42_29bc02ce3c49.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> arr = xr.DataArray(
...     data=[0, 1],
...     dims="x",
...     coords={"x": ["a", "b"], "y": ("x", [0, 1])},
... )
>>> arr
<xarray.DataArray (x: 2)> Size: 16B
array([0, 1])
Coordinates:
  * x        (x) <U1 8B 'a' 'b'
    y        (x) int64 16B 0 1
```

```pycon
>>> arr.swap_dims({"x": "y"})
<xarray.DataArray (y: 2)> Size: 16B
array([0, 1])
Coordinates:
  * y        (y) int64 16B 0 1
    x        (y) <U1 8B 'a' 'b'
```

```pycon
>>> arr.swap_dims({"x": "z"})
<xarray.DataArray (z: 2)> Size: 16B
array([0, 1])
Coordinates:
    x        (z) <U1 8B 'a' 'b'
    y        (z) int64 16B 0 1
Dimensions without coordinates: z
```

<div id="ee4b507f-7e53-434e-a439-82054f2296c4" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('98933dc9-e9e8-4376-9c93-350f9318302e','ee4b507f-7e53-434e-a439-82054f2296c4')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('98933dc9-e9e8-4376-9c93-350f9318302e','ee4b507f-7e53-434e-a439-82054f2296c4')">Open In Tab</button></div><div id="f112a42d-eac2-4df0-a3db-60167e8c2baa" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>

#### SEE ALSO
[`DataArray.rename`](xarray.DataArray.rename.html.md#xarray.DataArray.rename), [`Dataset.swap_dims`](xarray.Dataset.swap_dims.html.md#xarray.Dataset.swap_dims)
