# xarray.broadcast

### xarray.broadcast(\*args, exclude=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/structure/alignment.py#L1257-L1330)

Explicitly broadcast any number of DataArray or Dataset objects against
one another.

xarray objects automatically broadcast against each other in arithmetic
operations, so this function should not be necessary for normal use.

If no change is needed, the input data is returned to the output without
being copied.

* **Parameters:**
  * **\*args** ([`DataArray`](xarray.DataArray.html.md#xarray.DataArray) or [`Dataset`](xarray.Dataset.html.md#xarray.Dataset)) – Arrays to broadcast against each other.
  * **exclude** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [iterable](https://docs.python.org/3/glossary.html#term-iterable) of [hashable](../user-guide/terminology.html.md#term-name) or [`None`](https://docs.python.org/3/builtins/constants.html#None), *optional*) – Dimensions that must not be broadcasted
* **Returns:**
  **broadcast** ([`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple) of [`DataArray`](xarray.DataArray.html.md#xarray.DataArray) or [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple) of [`Dataset`](xarray.Dataset.html.md#xarray.Dataset)) – The same data as the input arrays, but with additional dimensions
  inserted so that all data arrays have the same dimensions and shape.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('e19bc4a4-8c60-4b16-8f7e-b0d8878023b2','02dec74c-579e-47f8-906d-f3154a22163a','5a12ae2f-271d-42fe-8a62-29125009a071','../lite/tree/../notebooks/index.html?path=fe6188e4_7603_4afa_93d1_cb1b680f3cde.ipynb','None')">Try it in your browser!</button></div>

Broadcast two data arrays against one another to fill out their dimensions:

```pycon
>>> a = xr.DataArray([1, 2, 3], dims="x")
>>> b = xr.DataArray([5, 6], dims="y")
>>> a
<xarray.DataArray (x: 3)> Size: 24B
array([1, 2, 3])
Dimensions without coordinates: x
>>> b
<xarray.DataArray (y: 2)> Size: 16B
array([5, 6])
Dimensions without coordinates: y
>>> a2, b2 = xr.broadcast(a, b)
>>> a2
<xarray.DataArray (x: 3, y: 2)> Size: 48B
array([[1, 1],
       [2, 2],
       [3, 3]])
Dimensions without coordinates: x, y
>>> b2
<xarray.DataArray (x: 3, y: 2)> Size: 48B
array([[5, 6],
       [5, 6],
       [5, 6]])
Dimensions without coordinates: x, y
```

Fill out the dimensions of all data variables in a dataset:

```pycon
>>> ds = xr.Dataset({"a": a, "b": b})
>>> (ds2,) = xr.broadcast(ds)  # use tuple unpacking to extract one dataset
>>> ds2
<xarray.Dataset> Size: 96B
Dimensions:  (x: 3, y: 2)
Dimensions without coordinates: x, y
Data variables:
    a        (x, y) int64 48B 1 1 2 2 3 3
    b        (x, y) int64 48B 5 6 5 6 5 6
```

<div id="5a12ae2f-271d-42fe-8a62-29125009a071" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('e19bc4a4-8c60-4b16-8f7e-b0d8878023b2','5a12ae2f-271d-42fe-8a62-29125009a071')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('e19bc4a4-8c60-4b16-8f7e-b0d8878023b2','5a12ae2f-271d-42fe-8a62-29125009a071')">Open In Tab</button></div><div id="02dec74c-579e-47f8-906d-f3154a22163a" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
