# 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('841b3d76-a6c3-4161-86e3-c67b262b8b82','e4a98566-0ff9-4c0e-8ed1-01732e49e648','65f3f90d-a647-4336-b285-2cd06990d7e9','../lite/tree/../notebooks/index.html?path=c4e5a3c3_c2ff_4856_878d_fb0bf808ae7c.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="65f3f90d-a647-4336-b285-2cd06990d7e9" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('841b3d76-a6c3-4161-86e3-c67b262b8b82','65f3f90d-a647-4336-b285-2cd06990d7e9')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('841b3d76-a6c3-4161-86e3-c67b262b8b82','65f3f90d-a647-4336-b285-2cd06990d7e9')">Open In Tab</button></div><div id="e4a98566-0ff9-4c0e-8ed1-01732e49e648" 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)
