ldexp

paddle. ldexp ( x, y, name=None ) [source]

Compute the result of multiplying x by 2 to the power of y. The equation is:

\[out = x * 2^{y}\]
Parameters
  • x (Tensor) – The input Tensor, the data type is float32, float64, int32 or int64.

  • y (Tensor) – A Tensor of exponents, typically integers.

  • name (str, optional) – Name for the operation (optional, default is None).For more information, please refer to Name.

Returns

An N-D Tensor. If x, y have different shapes and are “broadcastable”, the resulting tensor shape is the shape of x and y after broadcasting. If x, y have the same shape, its shape is the same as x and y. And the data type is float32 or float64.

Return type

out (Tensor)

Examples

>>> import paddle

>>> # example1
>>> x = paddle.to_tensor([1, 2, 3], dtype='float32')
>>> y = paddle.to_tensor([2, 3, 4], dtype='int32')
>>> res = paddle.ldexp(x, y)
>>> print(res)
Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
[4. , 16., 48.])

>>> # example2
>>> x = paddle.to_tensor([1, 2, 3], dtype='float32')
>>> y = paddle.to_tensor([2], dtype='int32')
>>> res = paddle.ldexp(x, y)
>>> print(res)
Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
[4. , 8. , 12.])