# xarray.ufuncs.fmod

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

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

Documentation from numpy:

Returns the element-wise remainder of division.

This is the NumPy implementation of the C library function fmod, the
remainder has the same sign as the dividend x1. It is equivalent to
the Matlab(TM) `rem` function and should not be confused with the
Python modulus operator `x1 % x2`.

* **Parameters:**
  * **x1** ([array_like](https://numpy.org/doc/stable/glossary.html#term-array_like)) – Dividend.
  * **x2** ([array_like](https://numpy.org/doc/stable/glossary.html#term-array_like)) – Divisor.
    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** ([array_like](https://numpy.org/doc/stable/glossary.html#term-array_like)) – The remainder of the division of x1 by x2.
  This is a scalar if both x1 and x2 are scalars.

#### SEE ALSO
[`remainder`](xarray.ufuncs.remainder.html.md#xarray.ufuncs.remainder)
: Equivalent to the Python `%` operator.

[`divide`](xarray.ufuncs.divide.html.md#xarray.ufuncs.divide)

### Notes

The result of the modulo operation for negative dividend and divisors
is bound by conventions. For fmod, the sign of result is the sign of
the dividend, while for remainder the sign of the result is the sign
of the divisor. The fmod function is equivalent to the Matlab(TM)
`rem` function.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('e79f1d52-e9fa-4073-9b8e-5079b9b22cbb','7df6cf70-e04f-4a4f-96c2-4638d3deb022','c8993e2e-887d-40e4-9bb6-4789b8e6dae7','../lite/tree/../notebooks/index.html?path=3fe83c67_5078_43db_969c_e397f9d3744e.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> import numpy as np
>>> np.fmod([-3, -2, -1, 1, 2, 3], 2)
array([-1,  0, -1,  1,  0,  1])
>>> np.remainder([-3, -2, -1, 1, 2, 3], 2)
array([1, 0, 1, 1, 0, 1])
```

```pycon
>>> np.fmod([5, 3], [2, 2.])
array([ 1.,  1.])
>>> a = np.arange(-3, 3).reshape(3, 2)
>>> a
array([[-3, -2],
       [-1,  0],
       [ 1,  2]])
>>> np.fmod(a, [2,2])
array([[-1,  0],
       [-1,  0],
       [ 1,  0]])
```

<div id="c8993e2e-887d-40e4-9bb6-4789b8e6dae7" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('e79f1d52-e9fa-4073-9b8e-5079b9b22cbb','c8993e2e-887d-40e4-9bb6-4789b8e6dae7')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('e79f1d52-e9fa-4073-9b8e-5079b9b22cbb','c8993e2e-887d-40e4-9bb6-4789b8e6dae7')">Open In Tab</button></div><div id="7df6cf70-e04f-4a4f-96c2-4638d3deb022" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
