Skip to content

Commit

Permalink
add deg2rad & rad2deg docs (PaddlePaddle#4121)
Browse files Browse the repository at this point in the history
* add deg2rad & rad2deg docs

* fix file name
  • Loading branch information
luotao1 authored Dec 2, 2021
1 parent cb49f94 commit 47d7dc4
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/api/paddle/Overview_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ tensor数学操作
" :ref:`paddle.diagonal <cn_api_tensor_diagonal>` ", "根据给定的轴 axis 返回输入 Tensor 的局部视图"
" :ref:`paddle.trunc <cn_api_tensor_trunc>` ", "对输入 Tensor 每个元素的小数部分进行截断"
" :ref:`paddle.log1p <cn_api_paddle_tensor_log1p>` ", "该OP计算Log1p(加一的自然对数)结果"
" :ref:`paddle.rad2deg <cn_api_paddle_tensor_rad2deg>` ", "将元素从弧度的角度转换为度"
" :ref:`paddle.deg2rad <cn_api_paddle_tensor_deg2rad>` ", "将元素从度的角度转换为弧度"

.. _tensor_logic:

Expand Down
22 changes: 22 additions & 0 deletions docs/api/paddle/Tensor_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,17 @@ cumsum(axis=None, dtype=None, name=None)

请参考 :ref:`cn_api_tensor_cn_cumsum`

deg2rad(x, name=None)
:::::::::

将元素从度的角度转换为弧度

返回:计算后的Tensor

返回类型:Tensor

请参考 :ref:`cn_api_paddle_tensor_deg2rad`

detach()
:::::::::

Expand Down Expand Up @@ -1479,6 +1490,17 @@ prod(axis=None, keepdim=False, dtype=None, name=None)

请参考 :ref:`cn_api_tensor_cn_prod`

rad2deg(x, name=None)
:::::::::

将元素从弧度的角度转换为度

返回:计算后的Tensor

返回类型:Tensor

请参考 :ref:`cn_api_paddle_tensor_rad2deg`

rank()
:::::::::

Expand Down
44 changes: 44 additions & 0 deletions docs/api/paddle/deg2rad_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.. _cn_api_paddle_tensor_deg2rad:

deg2rad
-------------------------------

.. py:function:: paddle.deg2rad(x, name=None)
将元素从弧度的角度转换为度

.. math::
deg2rad(x)=\pi * x / 180
参数
:::::::::

- **x** (Tensor) - 输入的Tensor,数据类型为:int32、int64、float32、float64。
- **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。

返回
:::::::::

输出Tensor,与 ``x`` 维度相同、数据类型相同(输入为int时,输出数据类型为float32)。

代码示例
:::::::::

.. code-block:: python
import paddle
import numpy as np
x1 = paddle.to_tensor([180.0, -180.0, 360.0, -360.0, 90.0, -90.0])
result1 = paddle.deg2rad(x1)
print(result1)
# Tensor(shape=[6], dtype=float32, place=CUDAPlace(0), stop_gradient=True,
# [3.14159274, -3.14159274, 6.28318548, -6.28318548, 1.57079637,
# -1.57079637])
x2 = paddle.to_tensor(180)
result2 = paddle.deg2rad(x2)
print(result2)
# Tensor(shape=[1], dtype=float32, place=CUDAPlace(0), stop_gradient=True,
# [3.14159274])
50 changes: 50 additions & 0 deletions docs/api/paddle/rad2deg_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.. _cn_api_paddle_tensor_rad2deg:

rad2deg
-------------------------------

.. py:function:: paddle.rad2deg(x, name=None)
将元素从弧度的角度转换为度

.. math::
rad2deg(x)=180/ \pi * x
参数
:::::::::

- **x** (Tensor) - 输入的Tensor,数据类型为:int32、int64、float32、float64。
- **name** (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。

返回
:::::::::

输出Tensor,与 ``x`` 维度相同、数据类型相同(输入为int时,输出数据类型为float32)。

代码示例
:::::::::

.. code-block:: python
import paddle
import numpy as np
x1 = paddle.to_tensor([3.142, -3.142, 6.283, -6.283, 1.570, -1.570])
result1 = paddle.rad2deg(x1)
print(result1)
# Tensor(shape=[6], dtype=float32, place=CUDAPlace(0), stop_gradient=True,
# [180.02334595, -180.02334595, 359.98937988, -359.98937988,
# 9.95437622 , -89.95437622])
x2 = paddle.to_tensor(np.pi/2)
result2 = paddle.rad2deg(x2)
print(result2)
# Tensor(shape=[1], dtype=float32, place=CUDAPlace(0), stop_gradient=True,
# [90.])
x3 = paddle.to_tensor(1)
result3 = paddle.rad2deg(x3)
print(result3)
# Tensor(shape=[1], dtype=float32, place=CUDAPlace(0), stop_gradient=True,
# [57.29578018])

0 comments on commit 47d7dc4

Please sign in to comment.