|
| 1 | +.. _cn_api_paddle_tensor_rad2deg: |
| 2 | + |
| 3 | +rad2deg |
| 4 | +------------------------------- |
| 5 | + |
| 6 | +.. py:function:: paddle.rad2deg(x, name=None) |
| 7 | +
|
| 8 | +将元素从弧度的角度转换为度 |
| 9 | + |
| 10 | +.. math:: |
| 11 | +
|
| 12 | + rad2deg(x)=180/ \pi * x |
| 13 | +
|
| 14 | +参数 |
| 15 | +::::::::: |
| 16 | + |
| 17 | +- **x** (Tensor) - 输入的Tensor,数据类型为:int32、int64、float32、float64。 |
| 18 | +- **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。 |
| 19 | + |
| 20 | +返回 |
| 21 | +::::::::: |
| 22 | + |
| 23 | +输出Tensor,与 ``x`` 维度相同、数据类型相同(输入为int时,输出数据类型为float32)。 |
| 24 | + |
| 25 | +代码示例 |
| 26 | +::::::::: |
| 27 | + |
| 28 | +.. code-block:: python |
| 29 | +
|
| 30 | + import paddle |
| 31 | + import numpy as np |
| 32 | + |
| 33 | + x1 = paddle.to_tensor([3.142, -3.142, 6.283, -6.283, 1.570, -1.570]) |
| 34 | + result1 = paddle.rad2deg(x1) |
| 35 | + print(result1) |
| 36 | + # Tensor(shape=[6], dtype=float32, place=CUDAPlace(0), stop_gradient=True, |
| 37 | + # [180.02334595, -180.02334595, 359.98937988, -359.98937988, |
| 38 | + # 9.95437622 , -89.95437622]) |
| 39 | +
|
| 40 | + x2 = paddle.to_tensor(np.pi/2) |
| 41 | + result2 = paddle.rad2deg(x2) |
| 42 | + print(result2) |
| 43 | + # Tensor(shape=[1], dtype=float32, place=CUDAPlace(0), stop_gradient=True, |
| 44 | + # [90.]) |
| 45 | + |
| 46 | + x3 = paddle.to_tensor(1) |
| 47 | + result3 = paddle.rad2deg(x3) |
| 48 | + print(result3) |
| 49 | + # Tensor(shape=[1], dtype=float32, place=CUDAPlace(0), stop_gradient=True, |
| 50 | + # [57.29578018]) |
0 commit comments