ldexp(x1, x2, out=None, **kwargs)

Returns x1 * 2**x2, element-wise. The mantissas x1 and twos exponents x2 are used to construct floating point numbers x1 * 2**x2.

  • x1 (ndarray or scalar) – Array of multipliers.

  • x2 (ndarray or scalar, int) – Array of twos exponents.

  • out (ndarray, optional) – A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not, a freshly-allocated array is returned.


y – The result of x1 * 2**x2. This is a scalar if both x1 and x2 are scalars.

Return type

ndarray or scalar


Complex dtypes are not supported, they will raise a TypeError. Different from numpy, we allow x2 to be float besides int. ldexp is useful as the inverse of frexp, if used by itself it is more clear to simply use the expression x1 * 2**x2.


>>> np.ldexp(5, np.arange(4))
array([  5.,  10.,  20.,  40.])