# xarray.ufuncs.divide

### xarray.ufuncs.divide *= <xarray.ufuncs._binary_ufunc object>*

xarray specific variant of `numpy.divide()`. Handles xarray objects by dispatching to the appropriate function for the underlying array type.

Documentation from numpy:

Divide arguments element-wise.

* **Parameters:**
  * **x1** ([array_like](https://numpy.org/doc/stable/glossary.html#term-array_like)) – Dividend array.
  * **x2** ([array_like](https://numpy.org/doc/stable/glossary.html#term-array_like)) – Divisor array.
    If `x1.shape != x2.shape`, they must be broadcastable to a common
    shape (which becomes the shape of the output).
  * **out** ([`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray), [`None`](https://docs.python.org/3/builtins/constants.html#None), or [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple) of [`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray) and [`None`](https://docs.python.org/3/builtins/constants.html#None), *optional*) – A location into which the result is stored. If provided, it must have
    a shape that the inputs broadcast to. If not provided or None,
    a freshly-allocated array is returned. A tuple (possible only as a
    keyword argument) must have length equal to the number of outputs.
  * **where** ([array_like](https://numpy.org/doc/stable/glossary.html#term-array_like), *optional*) – This condition is broadcast over the input. At locations where the
    condition is True, the out array will be set to the ufunc result.
    Elsewhere, the out array will retain its original value.
    Note that if an uninitialized out array is created via the default
    `out=None`, locations within it where the condition is False will
    remain uninitialized.
  * **\*\*kwargs** – For other keyword-only arguments, see the
    [ufunc docs](https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs-kwargs).
* **Returns:**
  **y** ([`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray) or [scalar](../user-guide/terminology.html.md#term-scalar)) – The quotient `x1/x2`, element-wise.
  This is a scalar if both x1 and x2 are scalars.

#### SEE ALSO
`seterr`
: Set whether to raise or warn on overflow, underflow and division by zero.

### Notes

Equivalent to `x1` / `x2` in terms of array-broadcasting.

The `true_divide(x1, x2)` function is an alias for
`divide(x1, x2)`.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('82c304da-5d7f-4dde-a683-ade4f993943b','9891f11c-6cba-4773-9471-26eb9bac75bd','e8f3953d-1793-4ca4-a821-83921863943d','../lite/tree/../notebooks/index.html?path=652a2ef7_83b4_4fa4_b59c_8c3449d32d1d.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> import numpy as np
>>> np.divide(2.0, 4.0)
0.5
>>> x1 = np.arange(9.0).reshape((3, 3))
>>> x2 = np.arange(3.0)
>>> np.divide(x1, x2)
array([[nan, 1. , 1. ],
       [inf, 4. , 2.5],
       [inf, 7. , 4. ]])
```

The `/` operator can be used as a shorthand for `np.divide` on
ndarrays.

```pycon
>>> x1 = np.arange(9.0).reshape((3, 3))
>>> x2 = 2 * np.ones(3)
>>> x1 / x2
array([[0. , 0.5, 1. ],
       [1.5, 2. , 2.5],
       [3. , 3.5, 4. ]])
```

<div id="e8f3953d-1793-4ca4-a821-83921863943d" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('82c304da-5d7f-4dde-a683-ade4f993943b','e8f3953d-1793-4ca4-a821-83921863943d')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('82c304da-5d7f-4dde-a683-ade4f993943b','e8f3953d-1793-4ca4-a821-83921863943d')">Open In Tab</button></div><div id="9891f11c-6cba-4773-9471-26eb9bac75bd" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
