未验证 提交 ebc06c71 编写于 作者: Y Yang Zhang 提交者: GitHub

Update docs for `abs` `acos` `asin` `atan` `ceil` `cos` (#2326)

* Update docs for `abs` `acos` `asin` `atan` `ceil` `cos`

update code samples
`Variable` -> `Tensor`
remove activation wording
explain cos input/output range
misc fixes

* Apply input template

* Update `enable_imperative` -> `disable_static`
上级 22e3c254
...@@ -11,23 +11,29 @@ abs ...@@ -11,23 +11,29 @@ abs
绝对值激活函数。 绝对值函数。
.. math:: .. math::
out = |x| out = |x|
参数: 参数:
- **x** (Variable)- 多维Tensor,数据类型为float32或float64。 - x (Tensor) - 输入的Tensor,数据类型为:float32、float64。
- **name** (str) – 该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` ,默认值为None - name (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`
返回:表示绝对值结果的Tensor,数据类型与x相同。 返回:输出Tensor,与 ``x`` 维度相同、数据类型相同。
返回类型:Variable 返回类型:Tensor
**代码示例**: **代码示例**:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid import paddle
data = fluid.layers.data(name="input", shape=[32, 784]) import numpy as np
result = fluid.layers.abs(data)
paddle.disable_static()
x_data = np.array([-1, -2, -3, -4]).astype(np.float32)
x = paddle.to_variable(x_data)
res = paddle.abs(x)
print(res.numpy())
# [1, 2, 3, 4]
...@@ -11,29 +11,30 @@ acos ...@@ -11,29 +11,30 @@ acos
arccosine激活函数。 arccosine函数。
.. math:: .. math::
out = cos^{-1}(x) out = cos^{-1}(x)
参数: 参数:
- **x(Variable)** - acos的输入Tensor,数据类型为 float32 或 float64 - x (Tensor) - 输入的Tensor,数据类型为:float32、float64。
- **name** (str|None) – 具体用法请参见 :ref:`cn_api_guide_Name` ,一般无需设置,默认值为None。 - name (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。
返回: `acos` 的输出Tensor,数据类型与 `x` 相同。
返回类型: Variable 返回:输出Tensor,与 ``x`` 维度相同、数据类型相同。
返回类型: Tensor
**代码示例**: **代码示例**:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid import paddle
data = fluid.layers.data(name="input", shape=[4]) import numpy as np
# if data is [-0.8183, 0.4912, -0.6444, 0.0371]
result = fluid.layers.acos(data)
# result is [2.5293, 1.0573, 2.2711, 1.5336]
paddle.disable_static()
x_data = np.array([-0.8183, 0.4912, -0.6444, 0.0371]).astype(np.float32)
x = paddle.to_variable(x_data)
res = paddle.acos(x)
print(res.numpy())
# [2.5293, 1.0573, 2.2711, 1.5336]
...@@ -11,29 +11,29 @@ asin ...@@ -11,29 +11,29 @@ asin
arcsine激活函数。 arcsine函数。
.. math:: .. math::
out = sin^{-1}(x) out = sin^{-1}(x)
参数: 参数:
- **x(Variable)** - asin的输入Tensor,数据类型为 float32 或 float64 - x (Tensor) - 输入的Tensor,数据类型为:float32、float64。
- **name** (str|None) – 具体用法请参见 :ref:`cn_api_guide_Name` ,一般无需设置,默认值为None - name (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`
返回: `asin` 的输出Tensor,数据类型与 `x` 相同。 返回:输出Tensor,与 ``x`` 维度相同、数据类型相同。
返回类型: Variable 返回类型: Tensor
**代码示例**: **代码示例**:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid import paddle
data = fluid.layers.data(name="input", shape=[4]) import numpy as np
# if data is [-0.8183, 0.4912, -0.6444, 0.0371]
result = fluid.layers.asin(data)
# result is [-0.9585, 0.5135, -0.7003, 0.0372]
paddle.disable_static()
x_data = np.array([-0.8183, 0.4912, -0.6444, 0.0371]).astype(np.float32)
x = paddle.to_variable(x_data)
res = paddle.asin(x)
print(res.numpy())
# [-0.9585, 0.5135, -0.7003, 0.0372]
...@@ -11,30 +11,29 @@ atan ...@@ -11,30 +11,29 @@ atan
arctanh激活函数。 arctangent函数。
.. math:: .. math::
out = tanh^{-1}(x) out = tan^{-1}(x)
参数: 参数:
- **x(Variable)** - atan的输入Tensor,数据类型为 float32 或 float64 - x (Tensor) - 输入的Tensor,数据类型为:float32、float64。
- **name** (str|None) – 具体用法请参见 :ref:`cn_api_guide_Name` ,一般无需设置,默认值为None - name (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`
返回: `atan` 的输出Tensor,数据类型与 `x` 相同。 返回:输出Tensor,与 ``x`` 维度相同、数据类型相同。
返回类型: Variable 返回类型: Tensor
**代码示例**: **代码示例**:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid import paddle
data = fluid.layers.data(name="input", shape=[4]) import numpy as np
# if data is [-0.8183, 0.4912, -0.6444, 0.0371]
result = fluid.layers.atan(data)
# result is [-0.6858, 0.4566, -0.5724, 0.0371]
paddle.disable_static()
x_data = np.array([-0.8183, 0.4912, -0.6444, 0.0371]).astype(np.float32)
x = paddle.to_variable(x_data)
res = paddle.atan(x)
print(res.numpy())
# [-0.6858, 0.4566, -0.5724, 0.0371]
...@@ -19,24 +19,24 @@ ceil ...@@ -19,24 +19,24 @@ ceil
参数: 参数:
- **x** (Variable) - 该OP的输入为多维Tensor。数据类型为float32或float64。 - x (Tensor) - 输入的Tensor,数据类型为:float32、float64。
- **name** (str, 可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为None - name (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`
返回: 输出为Tensor,与 ``x`` 维度相同、数据类型相同。 返回:输出Tensor,与 ``x`` 维度相同、数据类型相同。
返回类型: Variable 返回类型: Tensor
**代码示例**: **代码示例**:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid import paddle
import numpy as np import numpy as np
input_ceil = np.array([[-1.5,6],[1,15.6]]) paddle.disable_static()
with fluid.dygraph.guard(): x_data = np.array([[-1.5,6],[1,15.6]]).astype(np.float32)
x = fluid.dygraph.to_variable(input_ceil) x = paddle.to_variable(x_data)
y = fluid.layers.ceil(x) res = paddle.ceil(x)
print(y.numpy()) print(res.numpy())
# [[-1. 6.] # [[-1. 6.]
# [ 1. 16.]] # [ 1. 16.]]
...@@ -13,32 +13,31 @@ cos ...@@ -13,32 +13,31 @@ cos
余弦函数。 余弦函数。
输入范围是 `(-inf, inf)` , 输出范围是 `[-1,1]`。若输入超出边界则结果为`nan`。
.. math:: .. math::
out = cos(x) out = cos(x)
参数: 参数:
- **x** (Variable) - 该OP的输入为多维Tensor,数据类型为float32,float64。 - x (Tensor) - 输入的Tensor,数据类型为:float32、float64。
- **name** (str, 可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为None。 - name (str,可选) - 操作的名称(可选,默认值为None)。更多信息请参见 :ref:`api_guide_Name`。
返回:输出Tensor,与 ``x`` 维度相同、数据类型相同。 返回:输出Tensor,与 ``x`` 维度相同、数据类型相同。
返回类型:Variable 返回类型:Tensor
**代码示例**: **代码示例**:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid import paddle
import numpy as np import numpy as np
input_cos = np.array([[-1,np.pi],[1,15.6]]) paddle.disable_static()
with fluid.dygraph.guard(): x_data = np.array([[-1,np.pi],[1,15.6]]).astype(np.float32)
x = fluid.dygraph.to_variable(input_cos) x = paddle.to_variable(x_data)
y = fluid.layers.cos(x) res = paddle.cos(x)
print(y.numpy()) print(res.numpy())
# [[ 0.54030231 -1. ] # [[ 0.54030231 -1. ]
# [ 0.54030231 -0.99417763]] # [ 0.54030231 -0.99417763]]
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册