# xarray.ufuncs.ldexp

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

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

Documentation from numpy:

Returns x1 \* 2\*\*x2, element-wise.

The mantissas x1 and twos exponents x2 are used to construct
floating point numbers `x1 * 2**x2`.

* **Parameters:**
  * **x1** ([array_like](https://numpy.org/doc/stable/glossary.html#term-array_like)) – Array of multipliers.
  * **x2** ([array_like](https://numpy.org/doc/stable/glossary.html#term-array_like), [`int`](https://docs.python.org/3/builtins/functions.html#int)) – Array of twos exponents.
    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 result of `x1 * 2**x2`.
  This is a scalar if both x1 and x2 are scalars.

#### SEE ALSO
`frexp`
: Return (y1, y2) from `x = y1 * 2**y2`, inverse to ldexp.

### Notes

Complex dtypes are not supported, they will raise a TypeError.

ldexp is useful as the inverse of frexp, if used by itself it is
more clear to simply use the expression `x1 * 2**x2`.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('1783151d-1584-4864-9dd4-edda72c6658c','2598fe36-6883-4870-8efa-7d7792cf5c3b','6ae3a4cc-f464-4ed4-bead-75ab6f468866','../lite/tree/../notebooks/index.html?path=1fff645b_a740_4e03_b099_662b60c8a2b5.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> import numpy as np
>>> np.ldexp(5, np.arange(4))
array([ 5., 10., 20., 40.], dtype=float16)
```

```pycon
>>> x = np.arange(6)
>>> np.ldexp(*np.frexp(x))
array([ 0.,  1.,  2.,  3.,  4.,  5.])
```

<div id="6ae3a4cc-f464-4ed4-bead-75ab6f468866" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('1783151d-1584-4864-9dd4-edda72c6658c','6ae3a4cc-f464-4ed4-bead-75ab6f468866')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('1783151d-1584-4864-9dd4-edda72c6658c','6ae3a4cc-f464-4ed4-bead-75ab6f468866')">Open In Tab</button></div><div id="2598fe36-6883-4870-8efa-7d7792cf5c3b" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
