pow
指数算子,逐元素计算 x 的 y 次幂。
\[out = x^{y}\]
参数
x (Tensor)- 多维
Tensor,数据类型为bfloat16、float16、float32、float64、int32或int64。y (float|int|Tensor)- 如果类型是多维
Tensor,其数据类型应该和x相同。name (str,可选) - 具体用法请参见 Name,一般无需设置,默认值为 None。
返回
Tensor,维度和数据类型都和 x 相同。
代码示例
>>> 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.])