|
| 1 | +.. _cn_api_paddle_atan2: |
| 2 | + |
| 3 | +atan2 |
| 4 | +------------------------------- |
| 5 | + |
| 6 | +.. py:function:: paddle.atan2(y, x, name=None) |
| 7 | +
|
| 8 | +
|
| 9 | +
|
| 10 | +
|
| 11 | +对y/x进行逐元素的arctangent运算,通过符号确定象限 |
| 12 | + |
| 13 | +.. math:: |
| 14 | + atan2(y,x)=\left\{\begin{matrix} |
| 15 | + & tan^{-1}(\frac{y}{x}) & x > 0 \\ |
| 16 | + & tan^{-1}(\frac{y}{x}) + \pi & y>=0, x < 0 \\ |
| 17 | + & tan^{-1}(\frac{y}{x}) - \pi & y<0, x < 0 \\ |
| 18 | + & +\frac{\pi}{2} & y>0, x = 0 \\ |
| 19 | + & -\frac{\pi}{2} & y<0, x = 0 \\ |
| 20 | + &\text{undefined} & y=0, x = 0 |
| 21 | + \end{matrix}\right. |
| 22 | +
|
| 23 | +
|
| 24 | +参数 |
| 25 | +::::::::: |
| 26 | + |
| 27 | +- **y** (Tensor) - 输入的Tensor,数据类型为:float16、float32、float64。 |
| 28 | +- **x** (Tensor) - 输入的Tensor,数据类型为:float16、float32、float64。 |
| 29 | +- **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 |
| 30 | + |
| 31 | +返回 |
| 32 | +::::::::: |
| 33 | + |
| 34 | +输出Tensor,与 ``x`` 维度相同、数据类型相同。 |
| 35 | + |
| 36 | +代码示例 |
| 37 | +::::::::: |
| 38 | + |
| 39 | +.. code-block:: python |
| 40 | +
|
| 41 | + import paddle |
| 42 | +
|
| 43 | + y = paddle.to_tensor([-1, +1, +1, -1]).astype('float32') |
| 44 | + #Tensor(shape=[4], dtype=float32, place=CUDAPlace(0), stop_gradient=True, |
| 45 | + # [-1, 1, 1, -1]) |
| 46 | +
|
| 47 | + x = paddle.to_tensor([-1, -1, +1, +1]).astype('float32') |
| 48 | + #Tensor(shape=[4], dtype=float32, place=CUDAPlace(0), stop_gradient=True, |
| 49 | + # [-1, -1, 1, 1]) |
| 50 | +
|
| 51 | + out = paddle.atan2(y, x) |
| 52 | + #Tensor(shape=[4], dtype=float32, place=CUDAPlace(0), stop_gradient=True, |
| 53 | + # [-2.35619450, 2.35619450, 0.78539819, -0.78539819]) |
0 commit comments