pow

paddle. pow ( x: Tensor, y: float | Tensor, name: str | None = None, *, out: Tensor | None = None ) Tensor [source]

Compute the power of Tensor elements. The equation is:

\[out = x^{y}\]

Note

paddle.pow supports broadcasting. If you want know more about broadcasting, please refer to Introduction to Tensor .

Note

Alias Support: The parameter name input can be used as an alias for x, The parameter name exponent can be used as an alias for y. For example, pow(input=2, exponent=1.1) is equivalent to pow(x=2, y=1.1).

Parameters
  • x (Tensor) – An N-D Tensor, the data type is bfloat16, float16, float32, float64, int32, int64, complex64 or complex128.

  • input – An alias for x , with identical behavior.

  • y (float|int|Tensor) – If it is an N-D Tensor, its data type should be the same as x.

  • exponent – An alias for y , with identical behavior.

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

  • out (Tensor, optional) – The output tensor. If set, the result will be stored in this tensor. Default is None.

Returns

N-D Tensor. A location into which the result is stored. Its dimension and data type are the same as x.

Examples

>>> import paddle

>>> x = paddle.to_tensor([1, 2, 3], dtype='float32')

>>> # example 1: y is a float or int
>>> res = paddle.pow(x, 2)
>>> print(res)
Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
[1., 4., 9.])
>>> res = paddle.pow(x, 2.5)
>>> print(res)
Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
[1.         , 5.65685415 , 15.58845711])

>>> # example 2: y is a Tensor
>>> y = paddle.to_tensor([2], dtype='float32')
>>> res = paddle.pow(x, y)
>>> print(res)
Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
[1., 4., 9.])