Compute the power of Tensor elements. The equation is: .. math:: out = x^{y} Note: ``paddle.pow`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . .. _Introduction to Tensor: ../../guides/beginner/ten
(
x: Tensor,
y: float | Tensor,
name: str | None = None,
*,
out: Tensor | None = None,
)
| 542 | |
| 543 | @param_two_alias(["x", "input"], ["y", "exponent"]) |
| 544 | def pow( |
| 545 | x: Tensor, |
| 546 | y: float | Tensor, |
| 547 | name: str | None = None, |
| 548 | *, |
| 549 | out: Tensor | None = None, |
| 550 | ) -> Tensor: |
| 551 | """ |
| 552 | Compute the power of Tensor elements. The equation is: |
| 553 | |
| 554 | .. math:: |
| 555 | out = x^{y} |
| 556 | |
| 557 | Note: |
| 558 | ``paddle.pow`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . |
| 559 | |
| 560 | .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor |
| 561 | |
| 562 | .. note:: |
| 563 | 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``. |
| 564 | For example, ``pow(input=2, exponent=1.1)`` is equivalent to ``pow(x=2, y=1.1)``. |
| 565 | |
| 566 | Args: |
| 567 | x (Tensor): An N-D Tensor, the data type is bfloat16, float16, float32, float64, int32, int64, complex64 or complex128. |
| 568 | input: An alias for ``x`` , with identical behavior. |
| 569 | y (float|int|Tensor): If it is an N-D Tensor, its data type should be the same as `x`. |
| 570 | exponent: An alias for ``y`` , with identical behavior. |
| 571 | name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`. |
| 572 | out (Tensor, optional): The output tensor. If set, the result will be stored in this tensor. Default is None. |
| 573 | |
| 574 | Returns: |
| 575 | N-D Tensor. A location into which the result is stored. Its dimension and data type are the same as `x`. |
| 576 | |
| 577 | Examples: |
| 578 | |
| 579 | .. code-block:: pycon |
| 580 | |
| 581 | >>> import paddle |
| 582 | |
| 583 | >>> x = paddle.to_tensor([1, 2, 3], dtype='float32') |
| 584 | |
| 585 | >>> # example 1: y is a float or int |
| 586 | >>> res = paddle.pow(x, 2) |
| 587 | >>> print(res) |
| 588 | Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True, |
| 589 | [1., 4., 9.]) |
| 590 | >>> res = paddle.pow(x, 2.5) |
| 591 | >>> print(res) |
| 592 | Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True, |
| 593 | [1. , 5.65685415 , 15.58845711]) |
| 594 | |
| 595 | >>> # example 2: y is a Tensor |
| 596 | >>> y = paddle.to_tensor([2], dtype='float32') |
| 597 | >>> res = paddle.pow(x, y) |
| 598 | >>> print(res) |
| 599 | Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True, |
| 600 | [1., 4., 9.]) |
| 601 |
no test coverage detected