未验证 提交 e4ffcfe1 编写于 作者: G gongweibao 提交者: GitHub

Polish elementwise_max elementwise_min elementwise_pow documents (#1290)

Polish elementwise_max elementwise_min elementwise_pow documents 
上级 8c6a20ad
...@@ -4,22 +4,22 @@ elementwise_max ...@@ -4,22 +4,22 @@ elementwise_max
------------------------------- -------------------------------
.. py:function:: paddle.fluid.layers.elementwise_max(x, y, axis=-1, act=None, name=None) .. py:function:: paddle.fluid.layers.elementwise_max(x, y, axis=-1, act=None, name=None)
最大元素算子 该OP逐元素对比输入的两个多维Tensor,并且把各个位置更大的元素保存到返回结果中。
等式是: 等式是:
.. math:: .. math::
Out = max(X, Y) Out = max(X, Y)
- :math:`X` :任何维度的张量(Tensor) - :math:`X` :多维Tensor
- :math:`Y` :维度必须小于或等于X维度的张量(Tensor) - :math:`Y` :多维Tensor
此运算算子有两种情况: 此运算算子有两种情况:
1. :math:`Y` 的形状(shape)与 :math:`X` 相同。 1. :math:`Y` 的 ``shape`` 与 :math:`X` 相同。
2. :math:`Y` 的形状(shape)是 :math:`X` 的连续子序列。 2. :math:`Y` 的 ``shape`` 是 :math:`X` 的连续子序列。
对于情况2: 对于情况2:
1. 用 :math:`Y` 匹配 :math:`X` 的形状(shape),其中 ``axis`` 将是 :math:`Y` 传到 :math:`X` 上的起始维度索引 1. 用 :math:`Y` 的 ``shape`` 匹配 :math:`X` 的 ``shape``,其中 ``axis`` 是 :math:`Y` 在 :math:`X` 上的起始维度的位置
2. 如果 ``axis`` 为-1(默认值),则 :math:`axis = rank(X)-rank(Y)` 。 2. 如果 ``axis`` 为-1(默认值),则 :math:`axis = rank(X)-rank(Y)` 。
3. 考虑到子序列, :math:`Y` 的大小为1的尾部维度将被忽略,例如shape(Y)=(2,1)=>(2)。 3. 考虑到子序列, :math:`Y` 的大小为1的尾部维度将被忽略,例如shape(Y)=(2,1)=>(2)。
...@@ -34,51 +34,65 @@ elementwise_max ...@@ -34,51 +34,65 @@ elementwise_max
shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0 shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0
shape(X) = (2, 3, 4, 5), shape(Y) = (2, 1), with axis=0 shape(X) = (2, 3, 4, 5), shape(Y) = (2, 1), with axis=0
输入X和Y可以携带不同的LoD信息。但输出仅与输入X共享LoD信息。
参数: 参数:
- **x** (Tensor)- 第一个输入张量(Tensor)。 - **x** (Variable)- 多维Tensor。数据类型为 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64`` 。
- **y** (Tensor)- 第二个输入张量(Tensor)。 - **y** (Variable)- 多维Tensor。数据类型为 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64`` 。
- **axis** (INT)- (int,默认-1)。将Y传到X上的起始维度索引。 - **axis** (int32, 可选)- Y的维度对应到X维度上时的索引。默认值为 -1。
- **act** (basestring | None)- 激活函数名称,应用于输出。 - **act** (string, 可选)- 激活函数名称,作用于输出上。默认值为None。详细请参考 :ref:`api_guide_activations` , 常见的激活函数有: ``relu`` ``tanh`` ``sigmoid`` 等。
- **name** (basestring | None)- 输出的名称。 - **name** (string, 可选)- 输出的名字。默认值为None。该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` 。
返回: 维度和数据类型与 ``x`` 相同的多维Tensor。
返回类型: 多维Tensor。
**代码示例 1**
.. code-block:: python
import paddle.fluid as fluid
import numpy as np
返回: 元素运算的输出。 def gen_data():
return {
"x": np.array([2, 3, 4]),
"y": np.array([1, 5, 2])
}
**代码示例** x = fluid.layers.data(name="x", shape=[3], dtype='float32')
y = fluid.layers.data(name="y", shape=[3], dtype='float32')
z = fluid.layers.elementwise_max(x, y)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(),
fetch_list=[z.name])
print(z_value) #[2, 5, 4]
**代码示例 2**
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid import paddle.fluid as fluid
# 例1: shape(x) = (2, 3, 4, 5), shape(y) = (2, 3, 4, 5) import numpy as np
x0 = fluid.layers.data(name="x0", shape=[2, 3, 4, 5], dtype='float32')
y0 = fluid.layers.data(name="y0", shape=[2, 3, 4, 5], dtype='float32') def gen_data():
z0 = fluid.layers.elementwise_max(x0, y0) return {
"x": np.ones((2, 3, 4, 5)).astype('float32'),
# 例2: shape(X) = (2, 3, 4, 5), shape(Y) = (5) "y": np.zeros((3, 4)).astype('float32')
x1 = fluid.layers.data(name="x1", shape=[2, 3, 4, 5], dtype='float32') }
y1 = fluid.layers.data(name="y1", shape=[5], dtype='float32')
z1 = fluid.layers.elementwise_max(x1, y1) x = fluid.layers.data(name="x", shape=[2,3,4,5], dtype='float32')
y = fluid.layers.data(name="y", shape=[3,4], dtype='float32')
# 例3: shape(X) = (2, 3, 4, 5), shape(Y) = (4, 5), with axis=-1(default) or axis=2 z = fluid.layers.elementwise_max(x, y, axis=1)
x2 = fluid.layers.data(name="x2", shape=[2, 3, 4, 5], dtype='float32')
y2 = fluid.layers.data(name="y2", shape=[4, 5], dtype='float32') place = fluid.CPUPlace()
z2 = fluid.layers.elementwise_max(x2, y2, axis=2) exe = fluid.Executor(place)
# 例4: shape(X) = (2, 3, 4, 5), shape(Y) = (3, 4), with axis=1 z_value = exe.run(feed=gen_data(),
x3 = fluid.layers.data(name="x3", shape=[2, 3, 4, 5], dtype='float32') fetch_list=[z.name])
y3 = fluid.layers.data(name="y3", shape=[3, 4], dtype='float32')
z3 = fluid.layers.elementwise_max(x3, y3, axis=1) print(z_value)#[[[[1., 1., 1., 1., 1.] .... [1., 1., 1., 1., 1.]]]]
# 例5: shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0
x4 = fluid.layers.data(name="x4", shape=[2, 3, 4, 5], dtype='float32')
y4 = fluid.layers.data(name="y4", shape=[2], dtype='float32')
z4 = fluid.layers.elementwise_max(x4, y4, axis=0)
# 例6: shape(X) = (2, 3, 4, 5), shape(Y) = (2, 1), with axis=0
x5 = fluid.layers.data(name="x5", shape=[2, 3, 4, 5], dtype='float32')
y5 = fluid.layers.data(name="y5", shape=[2], dtype='float32')
z5 = fluid.layers.elementwise_max(x5, y5, axis=0)
......
...@@ -4,23 +4,22 @@ elementwise_min ...@@ -4,23 +4,22 @@ elementwise_min
------------------------------- -------------------------------
.. py:function:: paddle.fluid.layers.elementwise_min(x, y, axis=-1, act=None, name=None) .. py:function:: paddle.fluid.layers.elementwise_min(x, y, axis=-1, act=None, name=None)
该OP逐元素对比输入的两个多维Tensor,并且把各个位置更小的元素保存到返回结果中。
最小元素算子
等式是: 等式是:
.. math:: .. math::
Out = min(X, Y) Out = min(X, Y)
- :math:`X` :任何维度的张量(Tensor) - :math:`X` :多维Tensor
- :math:`Y` :维度必须小于或等于X维度的张量(Tensor) - :math:`Y` :多维Tensor
此运算算子有两种情况: 此运算算子有两种情况:
1. :math:`Y` 的形状(shape)与 :math:`X` 相同。 1. :math:`Y` 的 ``shape`` 与 :math:`X` 相同。
2. :math:`Y` 的形状(shape)是 :math:`X` 的连续子序列。 2. :math:`Y` 的 ``shape`` 是 :math:`X` 的连续子序列。
对于情况2: 对于情况2:
1. 用 :math:`Y` 匹配 :math:`X` 的形状(shape),其中 ``axis`` 将是 :math:`Y` 传到 :math:`X` 上的起始维度索引 1. 用 :math:`Y` 的 ``shape`` 匹配 :math:`X` 的 ``shape``,其中 ``axis`` 是 :math:`Y` 在 :math:`X` 上的起始维度的位置
2. 如果 ``axis`` 为-1(默认值),则 :math:`axis = rank(X)-rank(Y)` 。 2. 如果 ``axis`` 为-1(默认值),则 :math:`axis = rank(X)-rank(Y)` 。
3. 考虑到子序列, :math:`Y` 的大小为1的尾部维度将被忽略,例如shape(Y)=(2,1)=>(2)。 3. 考虑到子序列, :math:`Y` 的大小为1的尾部维度将被忽略,例如shape(Y)=(2,1)=>(2)。
...@@ -35,52 +34,65 @@ elementwise_min ...@@ -35,52 +34,65 @@ elementwise_min
shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0 shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0
shape(X) = (2, 3, 4, 5), shape(Y) = (2, 1), with axis=0 shape(X) = (2, 3, 4, 5), shape(Y) = (2, 1), with axis=0
输入X和Y可以携带不同的LoD信息。但输出仅与输入X共享LoD信息。
参数: 参数:
- **x** (Tensor)- 第一个输入张量(Tensor)。 - **x** (Variable)- 多维Tensor。数据类型为 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64`` 。
- **y** (Tensor)- 第二个输入张量(Tensor)。 - **y** (Variable)- 多维Tensor。数据类型为 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64`` 。
- **axis** (INT)- (int,默认-1)。将Y传到X上的起始维度索引。 - **axis** (int32, 可选)- Y的维度对应到X维度上时的索引。默认值为 -1。
- **act** (basestring | None)- 激活函数名称,应用于输出。 - **act** (string, 可选)- 激活函数名称,作用于输出上。默认值为None。详细请参考 :ref:`api_guide_activations` , 常见的激活函数有: ``relu`` ``tanh`` ``sigmoid`` 等。
- **name** (basestring | None)- 输出的名称。 - **name** (string, 可选)- 输出的名字。默认值为None。该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` 。
返回: 维度和数据类型与 ``x`` 相同的多维Tensor。
返回: 元素运算的输出 返回类型: 多维Tensor
**代码示例** **代码示例 1**
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid import paddle.fluid as fluid
# 例1: shape(x) = (2, 3, 4, 5), shape(y) = (2, 3, 4, 5) import numpy as np
x0 = fluid.layers.data(name="x0", shape=[2, 3, 4, 5], dtype='float32')
y0 = fluid.layers.data(name="y0", shape=[2, 3, 4, 5], dtype='float32') def gen_data():
z0 = fluid.layers.elementwise_min(x0, y0) return {
"x": np.array([2, 3, 4]),
# 例2: shape(X) = (2, 3, 4, 5), shape(Y) = (5) "y": np.array([1, 5, 2])
x1 = fluid.layers.data(name="x1", shape=[2, 3, 4, 5], dtype='float32') }
y1 = fluid.layers.data(name="y1", shape=[5], dtype='float32')
z1 = fluid.layers.elementwise_min(x1, y1) x = fluid.layers.data(name="x", shape=[3], dtype='float32')
y = fluid.layers.data(name="y", shape=[3], dtype='float32')
# 例3: shape(X) = (2, 3, 4, 5), shape(Y) = (4, 5), with axis=-1(default) or axis=2 z = fluid.layers.elementwise_max(x, y)
x2 = fluid.layers.data(name="x2", shape=[2, 3, 4, 5], dtype='float32')
y2 = fluid.layers.data(name="y2", shape=[4, 5], dtype='float32') place = fluid.CPUPlace()
z2 = fluid.layers.elementwise_min(x2, y2, axis=2) exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(),
# 例4: shape(X) = (2, 3, 4, 5), shape(Y) = (3, 4), with axis=1 fetch_list=[z.name])
x3 = fluid.layers.data(name="x3", shape=[2, 3, 4, 5], dtype='float32')
y3 = fluid.layers.data(name="y3", shape=[3, 4], dtype='float32') print(z_value) #[1, 3, 2]
z3 = fluid.layers.elementwise_min(x3, y3, axis=1)
**代码示例 2**
# 例5: shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0
x4 = fluid.layers.data(name="x4", shape=[2, 3, 4, 5], dtype='float32') .. code-block:: python
y4 = fluid.layers.data(name="y4", shape=[2], dtype='float32')
z4 = fluid.layers.elementwise_min(x4, y4, axis=0) import paddle.fluid as fluid
import numpy as np
# 例6: shape(X) = (2, 3, 4, 5), shape(Y) = (2, 1), with axis=0
x5 = fluid.layers.data(name="x5", shape=[2, 3, 4, 5], dtype='float32') def gen_data():
y5 = fluid.layers.data(name="y5", shape=[2], dtype='float32') return {
z5 = fluid.layers.elementwise_min(x5, y5, axis=0) "x": np.ones((2, 3, 4, 5)).astype('float32'),
"y": np.zeros((3, 4)).astype('float32')
}
x = fluid.layers.data(name="x", shape=[2,3,4,5], dtype='float32')
y = fluid.layers.data(name="y", shape=[3,4], dtype='float32')
z = fluid.layers.elementwise_max(x, y, axis=1)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(),
fetch_list=[z.name])
print(z_value)#[[[[0., 0., 0., 0., 0.] .... [0., 0., 0., 0., 0.]]]]
......
...@@ -4,27 +4,26 @@ elementwise_pow ...@@ -4,27 +4,26 @@ elementwise_pow
------------------------------- -------------------------------
.. py:function:: paddle.fluid.layers.elementwise_pow(x, y, axis=-1, act=None, name=None) .. py:function:: paddle.fluid.layers.elementwise_pow(x, y, axis=-1, act=None, name=None)
该OP逐元素对输入Tensor进行幂操作。
逐元素幂运算算子
等式是: 等式是:
.. math:: .. math::
Out = X ^ Y Out = X ^ Y
- :math:`X` :任何维度的张量(Tensor) - :math:`X` :多维Tensor
- :math:`Y` :维度必须小于或等于X维度的张量(Tensor) - :math:`Y` :多维Tensor
此运算算子有两种情况: 此运算算子有两种情况:
1. :math:`Y` 的形状(shape)与 :math:`X` 相同。 1. :math:`Y` 的 ``shape`` 与 :math:`X` 相同。
2. :math:`Y` 的形状(shape)是 :math:`X` 的连续子序列。 2. :math:`Y` 的 ``shape`` 是 :math:`X` 的连续子序列。
对于情况2: 对于情况2:
1. 用 :math:`Y` 匹配 :math:`X` 的形状(shape),其中 ``axis`` 将是 :math:`Y` 传到 :math:`X` 上的起始维度索引 1. 用 :math:`Y` 的 ``shape`` 匹配 :math:`X` 的 ``shape``,其中 ``axis`` 是 :math:`Y` 在 :math:`X` 上的起始维度的位置
2. 如果 ``axis`` 为-1(默认值),则 :math:`axis = rank(X)-rank(Y)` 。 2. 如果 ``axis`` 为-1(默认值),则 :math:`axis = rank(X)-rank(Y)` 。
3. 考虑到子序列, :math:`Y` 的大小为1的尾维度将被忽略,例如shape(Y)=(2,1)=>(2)。 3. 考虑到子序列, :math:`Y` 的大小为1的尾维度将被忽略,例如shape(Y)=(2,1)=>(2)。
**代码示例** 例如:
.. code-block:: text .. code-block:: text
...@@ -35,56 +34,40 @@ elementwise_pow ...@@ -35,56 +34,40 @@ elementwise_pow
shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0 shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0
shape(X) = (2, 3, 4, 5), shape(Y) = (2, 1), with axis=0 shape(X) = (2, 3, 4, 5), shape(Y) = (2, 1), with axis=0
输入X和Y可以携带不同的LoD信息。但输出仅与输入X共享LoD信息。
参数: 参数:
- **x** (Tensor)- 第一个输入张量(Tensor)。 - **x** (Variable)- 多维Tensor。数据类型为 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64`` 。
- **y** (Tensor)- 第二个输入张量(Tensor)。 - **y** (Variable)- 多维Tensor。数据类型为 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64`` 。
- **axis** (INT)- (int,默认-1)。将Y传到X上的起始维度索引。 - **axis** (int32, 可选)- Y的维度对应到X维度上时的索引。默认值为 -1。
- **act** (basestring | None)- 激活函数名称,应用于输出。 - **act** (string, 可选)- 激活函数名称,作用于输出上。默认值为None。详细请参考 :ref:`api_guide_activations` , 常见的激活函数有: ``relu`` ``tanh`` ``sigmoid`` 等。
- **name** (basestring | None)- 输出的名称。 - **name** (string, 可选)- 输出的名字。默认值为None。该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` 。
返回: 维度和数据类型与 ``x`` 相同的多维Tensor。
返回: 元素运算的输出 返回类型: 多维Tensor
**代码示例** **代码示例**
.. code-block:: python .. code-block:: python
# 例1: shape(x) = (2, 3, 4, 5), shape(y) = (2, 3, 4, 5)
import paddle.fluid as fluid
x0 = fluid.layers.data(name="x0", shape=[2, 3, 4, 5], dtype='float32')
y0 = fluid.layers.data(name="y0", shape=[2, 3, 4, 5], dtype='float32')
z0 = fluid.layers.elementwise_pow(x0, y0)
# 例2: shape(X) = (2, 3, 4, 5), shape(Y) = (5)
import paddle.fluid as fluid
x1 = fluid.layers.data(name="x1", shape=[2, 3, 4, 5], dtype='float32')
y1 = fluid.layers.data(name="y1", shape=[5], dtype='float32')
z1 = fluid.layers.elementwise_pow(x1, y1)
# 例3: shape(X) = (2, 3, 4, 5), shape(Y) = (4, 5), with axis=-1(default) or axis=2
import paddle.fluid as fluid
x2 = fluid.layers.data(name="x2", shape=[2, 3, 4, 5], dtype='float32')
y2 = fluid.layers.data(name="y2", shape=[4, 5], dtype='float32')
z2 = fluid.layers.elementwise_pow(x2, y2, axis=2)
# 例4: shape(X) = (2, 3, 4, 5), shape(Y) = (3, 4), with axis=1
import paddle.fluid as fluid import paddle.fluid as fluid
x3 = fluid.layers.data(name="x3", shape=[2, 3, 4, 5], dtype='float32') import numpy as np
y3 = fluid.layers.data(name="y3", shape=[3, 4], dtype='float32')
z3 = fluid.layers.elementwise_pow(x3, y3, axis=1) def gen_data():
return {
# 例5: shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0 "x": np.array([2, 3, 4]),
import paddle.fluid as fluid "y": np.array([1, 5, 2])
x4 = fluid.layers.data(name="x4", shape=[2, 3, 4, 5], dtype='float32') }
y4 = fluid.layers.data(name="y4", shape=[2], dtype='float32')
z4 = fluid.layers.elementwise_pow(x4, y4, axis=0) x = fluid.layers.data(name="x", shape=[3], dtype='float32')
y = fluid.layers.data(name="y", shape=[3], dtype='float32')
# 例6: shape(X) = (2, 3, 4, 5), shape(Y) = (2, 1), with axis=0 z = fluid.layers.elementwise_pow(x, y)
import paddle.fluid as fluid
x5 = fluid.layers.data(name="x5", shape=[2, 3, 4, 5], dtype='float32') place = fluid.CPUPlace()
y5 = fluid.layers.data(name="y5", shape=[2], dtype='float32') exe = fluid.Executor(place)
z5 = fluid.layers.elementwise_pow(x5, y5, axis=0) z_value = exe.run(feed=gen_data(),
fetch_list=[z.name])
print(z_value) #[2, 243, 16]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册