未验证 提交 f8ef714b 编写于 作者: W wangchaochaohu 提交者: GitHub

fix the reduce api en doc (#20223) (#20450)

* fix the reduce api en doc test=document_fix test=develop

* fix the fluid.data test=develop test=document_fix

* fix the API.spec test=develop test=document_fix

* fix according the review test=develop test=document_fix

* fix the confilict test=develop test=document_fix
上级 dcdb6180
...@@ -155,11 +155,11 @@ paddle.fluid.layers.sequence_expand_as (ArgSpec(args=['x', 'y', 'name'], varargs ...@@ -155,11 +155,11 @@ paddle.fluid.layers.sequence_expand_as (ArgSpec(args=['x', 'y', 'name'], varargs
paddle.fluid.layers.sequence_pad (ArgSpec(args=['x', 'pad_value', 'maxlen', 'name'], varargs=None, keywords=None, defaults=(None, None)), ('document', 'df08b9c499ab3a90f95d08ab5b6c6c62')) paddle.fluid.layers.sequence_pad (ArgSpec(args=['x', 'pad_value', 'maxlen', 'name'], varargs=None, keywords=None, defaults=(None, None)), ('document', 'df08b9c499ab3a90f95d08ab5b6c6c62'))
paddle.fluid.layers.sequence_unpad (ArgSpec(args=['x', 'length', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'e478180d5bc010a84f35af958cafa62c')) paddle.fluid.layers.sequence_unpad (ArgSpec(args=['x', 'length', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'e478180d5bc010a84f35af958cafa62c'))
paddle.fluid.layers.lstm_unit (ArgSpec(args=['x_t', 'hidden_t_prev', 'cell_t_prev', 'forget_bias', 'param_attr', 'bias_attr', 'name'], varargs=None, keywords=None, defaults=(0.0, None, None, None)), ('document', 'fe126c58e4339410e875ab1eba246d21')) paddle.fluid.layers.lstm_unit (ArgSpec(args=['x_t', 'hidden_t_prev', 'cell_t_prev', 'forget_bias', 'param_attr', 'bias_attr', 'name'], varargs=None, keywords=None, defaults=(0.0, None, None, None)), ('document', 'fe126c58e4339410e875ab1eba246d21'))
paddle.fluid.layers.reduce_sum (ArgSpec(args=['input', 'dim', 'keep_dim', 'name'], varargs=None, keywords=None, defaults=(None, False, None)), ('document', 'dd5f06fb7cf39ca06cbab4abd03e6893')) paddle.fluid.layers.reduce_sum (ArgSpec(args=['input', 'dim', 'keep_dim', 'name'], varargs=None, keywords=None, defaults=(None, False, None)), ('document', 'ecb55075fdf89a866bcede85e60aebad'))
paddle.fluid.layers.reduce_mean (ArgSpec(args=['input', 'dim', 'keep_dim', 'name'], varargs=None, keywords=None, defaults=(None, False, None)), ('document', 'a3024789eba11a70c2ef27c358173400')) paddle.fluid.layers.reduce_mean (ArgSpec(args=['input', 'dim', 'keep_dim', 'name'], varargs=None, keywords=None, defaults=(None, False, None)), ('document', '968c9b17affaf714e5021c3dc8d68c73'))
paddle.fluid.layers.reduce_max (ArgSpec(args=['input', 'dim', 'keep_dim', 'name'], varargs=None, keywords=None, defaults=(None, False, None)), ('document', '10023caec4d7f78c3b901f023a1feaa7')) paddle.fluid.layers.reduce_max (ArgSpec(args=['input', 'dim', 'keep_dim', 'name'], varargs=None, keywords=None, defaults=(None, False, None)), ('document', 'd37e3a9a05c00e032d4b7876c4f6b414'))
paddle.fluid.layers.reduce_min (ArgSpec(args=['input', 'dim', 'keep_dim', 'name'], varargs=None, keywords=None, defaults=(None, False, None)), ('document', '1a1c91625ce3c32646f69ca10d4d1da7')) paddle.fluid.layers.reduce_min (ArgSpec(args=['input', 'dim', 'keep_dim', 'name'], varargs=None, keywords=None, defaults=(None, False, None)), ('document', 'fad9e8057b48a075502b4d845f776b01'))
paddle.fluid.layers.reduce_prod (ArgSpec(args=['input', 'dim', 'keep_dim', 'name'], varargs=None, keywords=None, defaults=(None, False, None)), ('document', 'b386471f0476c80c61d8c8672278063d')) paddle.fluid.layers.reduce_prod (ArgSpec(args=['input', 'dim', 'keep_dim', 'name'], varargs=None, keywords=None, defaults=(None, False, None)), ('document', 'e165c6e99b1f5b773897c5910ccc7f4f'))
paddle.fluid.layers.reduce_all (ArgSpec(args=['input', 'dim', 'keep_dim', 'name'], varargs=None, keywords=None, defaults=(None, False, None)), ('document', 'e365c540ec448a73e2b2e75796ed029e')) paddle.fluid.layers.reduce_all (ArgSpec(args=['input', 'dim', 'keep_dim', 'name'], varargs=None, keywords=None, defaults=(None, False, None)), ('document', 'e365c540ec448a73e2b2e75796ed029e'))
paddle.fluid.layers.reduce_any (ArgSpec(args=['input', 'dim', 'keep_dim', 'name'], varargs=None, keywords=None, defaults=(None, False, None)), ('document', 'fbc9e73da7a2964ba5693864aed36abb')) paddle.fluid.layers.reduce_any (ArgSpec(args=['input', 'dim', 'keep_dim', 'name'], varargs=None, keywords=None, defaults=(None, False, None)), ('document', 'fbc9e73da7a2964ba5693864aed36abb'))
paddle.fluid.layers.sequence_first_step (ArgSpec(args=['input'], varargs=None, keywords=None, defaults=None), ('document', '227a75392ae194de0504f5c6812dade9')) paddle.fluid.layers.sequence_first_step (ArgSpec(args=['input'], varargs=None, keywords=None, defaults=None), ('document', '227a75392ae194de0504f5c6812dade9'))
......
...@@ -5884,21 +5884,27 @@ def reduce_sum(input, dim=None, keep_dim=False, name=None): ...@@ -5884,21 +5884,27 @@ def reduce_sum(input, dim=None, keep_dim=False, name=None):
Computes the sum of tensor elements over the given dimension. Computes the sum of tensor elements over the given dimension.
Args: Args:
input (Variable): The input variable which is a Tensor or LoDTensor. input (Variable): The input variable which is a Tensor, the data type is float32,
dim (list|int|None): The dimensions along which the sum is performed. If float64, int32, int64.
dim (list|int, optional): The dimensions along which the sum is performed. If
:attr:`None`, sum all elements of :attr:`input` and return a :attr:`None`, sum all elements of :attr:`input` and return a
Tensor variable with a single element, otherwise must be in the Tensor variable with a single element, otherwise must be in the
range :math:`[-rank(input), rank(input))`. If :math:`dim[i] < 0`, range :math:`[-rank(input), rank(input))`. If :math:`dim[i] < 0`,
the dimension to reduce is :math:`rank + dim[i]`. the dimension to reduce is :math:`rank + dim[i]`.
keep_dim (bool|False): Whether to reserve the reduced dimension in the keep_dim (bool, optional): Whether to reserve the reduced dimension in the
output Tensor. The result tensor will have one fewer dimension output Tensor. The result tensor will have one fewer dimension
than the :attr:`input` unless :attr:`keep_dim` is true. than the :attr:`input` unless :attr:`keep_dim` is true, default
name(str|None): A name for this layer(optional). If set None, the layer value is False.
will be named automatically. name(str, optional): The default value is None. Normally there is no need for
user to set this property. For more information, please refer to :ref:`api_guide_Name`
Returns: Returns:
Variable: The reduced Tensor variable. Variable: Tensor, results of summation operation on the specified dim of input tensor,
it's data type is the same as input's Tensor.
Raises:
TypeError, if out data type is different with the input data type.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -5907,7 +5913,7 @@ def reduce_sum(input, dim=None, keep_dim=False, name=None): ...@@ -5907,7 +5913,7 @@ def reduce_sum(input, dim=None, keep_dim=False, name=None):
# [[0.2, 0.3, 0.5, 0.9] # [[0.2, 0.3, 0.5, 0.9]
# [0.1, 0.2, 0.6, 0.7]] # [0.1, 0.2, 0.6, 0.7]]
# Each example is followed by the corresponding output tensor. # Each example is followed by the corresponding output tensor.
x = fluid.layers.data(name='x', shape=[4, 2], dtype='float32') x = fluid.data(name='x', shape=[2, 4], dtype='float32')
fluid.layers.reduce_sum(x) # [3.5] fluid.layers.reduce_sum(x) # [3.5]
fluid.layers.reduce_sum(x, dim=0) # [0.3, 0.5, 1.1, 1.6] fluid.layers.reduce_sum(x, dim=0) # [0.3, 0.5, 1.1, 1.6]
fluid.layers.reduce_sum(x, dim=-1) # [1.9, 1.6] fluid.layers.reduce_sum(x, dim=-1) # [1.9, 1.6]
...@@ -5917,7 +5923,7 @@ def reduce_sum(input, dim=None, keep_dim=False, name=None): ...@@ -5917,7 +5923,7 @@ def reduce_sum(input, dim=None, keep_dim=False, name=None):
# [[[1, 2], [3, 4]], # [[[1, 2], [3, 4]],
# [[5, 6], [7, 8]]] # [[5, 6], [7, 8]]]
# Each example is followed by the corresponding output tensor. # Each example is followed by the corresponding output tensor.
y = fluid.layers.data(name='y', shape=[2, 2, 2], dtype='float32') y = fluid.data(name='y', shape=[2, 2, 2], dtype='float32')
fluid.layers.reduce_sum(y, dim=[1, 2]) # [10, 26] fluid.layers.reduce_sum(y, dim=[1, 2]) # [10, 26]
fluid.layers.reduce_sum(y, dim=[0, 1]) # [16, 20] fluid.layers.reduce_sum(y, dim=[0, 1]) # [16, 20]
...@@ -5952,22 +5958,28 @@ def reduce_mean(input, dim=None, keep_dim=False, name=None): ...@@ -5952,22 +5958,28 @@ def reduce_mean(input, dim=None, keep_dim=False, name=None):
Computes the mean of the input tensor's elements along the given dimension. Computes the mean of the input tensor's elements along the given dimension.
Args: Args:
input (Variable): The input variable which is a Tensor or LoDTensor. input (Variable): The input variable which is a Tensor, the data type is float32,
dim (list|int|None): The dimension along which the mean is computed. If float64, int32, int64.
dim (list|int, optional): The dimension along which the mean is computed. If
`None`, compute the mean over all elements of :attr:`input` `None`, compute the mean over all elements of :attr:`input`
and return a variable with a single element, otherwise it and return a variable with a single element, otherwise it
must be in the range :math:`[-rank(input), rank(input))`. If must be in the range :math:`[-rank(input), rank(input))`. If
:math:`dim[i] < 0`, the dimension to reduce is :math:`dim[i] < 0`, the dimension to reduce is
:math:`rank(input) + dim[i]`. :math:`rank(input) + dim[i]`.
keep_dim (bool): Whether to reserve the reduced dimension in the keep_dim (bool, optional): Whether to reserve the reduced dimension in the
output Tensor. The result tensor will have one fewer dimension output Tensor. The result tensor will have one fewer dimension
than the :attr:`input` unless :attr:`keep_dim` is true. than the :attr:`input` unless :attr:`keep_dim` is true, default
name(str|None): A name for this layer(optional). If set `None`, the layer value is False.
will be named automatically. name(str, optional): The default value is None. Normally there is no need for
user to set this property. For more information, please refer to :ref:`api_guide_Name`
Returns: Returns:
Variable: The reduced mean Variable. Variable: Tensor, results of average on the specified dim of input tensor,
it's data type is the same as input's Tensor.
Raises:
TypeError, if out data type is different with the input data type.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -5976,7 +5988,7 @@ def reduce_mean(input, dim=None, keep_dim=False, name=None): ...@@ -5976,7 +5988,7 @@ def reduce_mean(input, dim=None, keep_dim=False, name=None):
# [[0.2, 0.3, 0.5, 0.9] # [[0.2, 0.3, 0.5, 0.9]
# [0.1, 0.2, 0.6, 0.7]] # [0.1, 0.2, 0.6, 0.7]]
# Each example is followed by the correspending output tensor. # Each example is followed by the correspending output tensor.
x = fluid.layers.data(name='x', shape=[4, 2], dtype='float32') x = fluid.data(name='x', shape=[2, 4], dtype='float32')
fluid.layers.reduce_mean(x) # [0.4375] fluid.layers.reduce_mean(x) # [0.4375]
fluid.layers.reduce_mean(x, dim=0) # [0.15, 0.25, 0.55, 0.8] fluid.layers.reduce_mean(x, dim=0) # [0.15, 0.25, 0.55, 0.8]
fluid.layers.reduce_mean(x, dim=-1) # [0.475, 0.4] fluid.layers.reduce_mean(x, dim=-1) # [0.475, 0.4]
...@@ -5986,7 +5998,7 @@ def reduce_mean(input, dim=None, keep_dim=False, name=None): ...@@ -5986,7 +5998,7 @@ def reduce_mean(input, dim=None, keep_dim=False, name=None):
# [[[1.0, 2.0], [3.0, 4.0]], # [[[1.0, 2.0], [3.0, 4.0]],
# [[5.0, 6.0], [7.0, 8.0]]] # [[5.0, 6.0], [7.0, 8.0]]]
# Each example is followed by the correspending output tensor. # Each example is followed by the correspending output tensor.
y = fluid.layers.data(name='y', shape=[2, 2, 2], dtype='float32') y = fluid.data(name='y', shape=[2, 2, 2], dtype='float32')
fluid.layers.reduce_mean(y, dim=[1, 2]) # [2.5, 6.5] fluid.layers.reduce_mean(y, dim=[1, 2]) # [2.5, 6.5]
fluid.layers.reduce_mean(y, dim=[0, 1]) # [4.0, 5.0] fluid.layers.reduce_mean(y, dim=[0, 1]) # [4.0, 5.0]
""" """
...@@ -6020,20 +6032,23 @@ def reduce_max(input, dim=None, keep_dim=False, name=None): ...@@ -6020,20 +6032,23 @@ def reduce_max(input, dim=None, keep_dim=False, name=None):
Computes the maximum of tensor elements over the given dimension. Computes the maximum of tensor elements over the given dimension.
Args: Args:
input (Variable): The input variable which is a Tensor or LoDTensor. input (Variable): The input variable which is a Tensor, the data type is float32,
dim (list|int|None): The dimension along which the maximum is computed. float64, int32, int64.
dim (list|int, optional): The dimension along which the maximum is computed.
If :attr:`None`, compute the maximum over all elements of If :attr:`None`, compute the maximum over all elements of
:attr:`input` and return a Tensor variable with a single element, :attr:`input` and return a Tensor variable with a single element,
otherwise must be in the range :math:`[-rank(input), rank(input))`. otherwise must be in the range :math:`[-rank(input), rank(input))`.
If :math:`dim[i] < 0`, the dimension to reduce is :math:`rank + dim[i]`. If :math:`dim[i] < 0`, the dimension to reduce is :math:`rank + dim[i]`.
keep_dim (bool): Whether to reserve the reduced dimension in the keep_dim (bool, optional): Whether to reserve the reduced dimension in the
output Tensor. The result tensor will have one fewer dimension output Tensor. The result tensor will have one fewer dimension
than the :attr:`input` unless :attr:`keep_dim` is true. than the :attr:`input` unless :attr:`keep_dim` is true, default
name(str|None): A name for this layer(optional). If set None, the layer value is False.
will be named automatically. name(str, optional): The default value is None. Normally there is no need for
user to set this property. For more information, please refer to :ref:`api_guide_Name`
Returns: Returns:
Variable: The reduced Tensor variable. Variable: Tensor, results of maximum on the specified dim of input tensor,
it's data type is the same as input's Tensor.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -6043,7 +6058,7 @@ def reduce_max(input, dim=None, keep_dim=False, name=None): ...@@ -6043,7 +6058,7 @@ def reduce_max(input, dim=None, keep_dim=False, name=None):
# [[0.2, 0.3, 0.5, 0.9] # [[0.2, 0.3, 0.5, 0.9]
# [0.1, 0.2, 0.6, 0.7]] # [0.1, 0.2, 0.6, 0.7]]
# Each example is followed by the correspending output tensor. # Each example is followed by the correspending output tensor.
x = fluid.layers.data(name='x', shape=[4, 2], dtype='float32') x = fluid.data(name='x', shape=[2, 4], dtype='float32')
fluid.layers.reduce_max(x) # [0.9] fluid.layers.reduce_max(x) # [0.9]
fluid.layers.reduce_max(x, dim=0) # [0.2, 0.3, 0.6, 0.9] fluid.layers.reduce_max(x, dim=0) # [0.2, 0.3, 0.6, 0.9]
fluid.layers.reduce_max(x, dim=-1) # [0.9, 0.7] fluid.layers.reduce_max(x, dim=-1) # [0.9, 0.7]
...@@ -6053,7 +6068,7 @@ def reduce_max(input, dim=None, keep_dim=False, name=None): ...@@ -6053,7 +6068,7 @@ def reduce_max(input, dim=None, keep_dim=False, name=None):
# [[[1.0, 2.0], [3.0, 4.0]], # [[[1.0, 2.0], [3.0, 4.0]],
# [[5.0, 6.0], [7.0, 8.0]]] # [[5.0, 6.0], [7.0, 8.0]]]
# Each example is followed by the correspending output tensor. # Each example is followed by the correspending output tensor.
y = fluid.layers.data(name='y', shape=[2, 2, 2], dtype='float32') y = fluid.data(name='y', shape=[2, 2, 2], dtype='float32')
fluid.layers.reduce_max(y, dim=[1, 2]) # [4.0, 8.0] fluid.layers.reduce_max(y, dim=[1, 2]) # [4.0, 8.0]
fluid.layers.reduce_max(y, dim=[0, 1]) # [7.0, 8.0] fluid.layers.reduce_max(y, dim=[0, 1]) # [7.0, 8.0]
""" """
...@@ -6078,20 +6093,23 @@ def reduce_min(input, dim=None, keep_dim=False, name=None): ...@@ -6078,20 +6093,23 @@ def reduce_min(input, dim=None, keep_dim=False, name=None):
Computes the minimum of tensor elements over the given dimension. Computes the minimum of tensor elements over the given dimension.
Args: Args:
input (Variable): The input variable which is a Tensor or LoDTensor. input (Variable): The input variable which is a Tensor, the data type is float32,
dim (list|int|None): The dimensions along which the minimum is computed. float64, int32, int64.
dim (list|int, optional): The dimensions along which the minimum is computed.
If :attr:`None`, compute the minimum over all elements of If :attr:`None`, compute the minimum over all elements of
:attr:`input` and return a Tensor variable with a single element, :attr:`input` and return a Tensor variable with a single element,
otherwise must be in the range :math:`[-rank(input), rank(input))`. otherwise must be in the range :math:`[-rank(input), rank(input))`.
If :math:`dim[i] < 0`, the dimension to reduce is :math:`rank + dim[i]`. If :math:`dim[i] < 0`, the dimension to reduce is :math:`rank + dim[i]`.
keep_dim (bool): Whether to reserve the reduced dimension in the keep_dim (bool, optional): Whether to reserve the reduced dimension in the
output Tensor. The result tensor will have one fewer dimension output Tensor. The result tensor will have one fewer dimension
than the :attr:`input` unless :attr:`keep_dim` is true. than the :attr:`input` unless :attr:`keep_dim` is true, default
name(str|None): A name for this layer(optional). If set None, the layer value is False.
will be named automatically. name(str, optional): The default value is None. Normally there is no need for
user to set this property. For more information, please refer to :ref:`api_guide_Name`
Returns: Returns:
Variable: The reduced Tensor variable. Variable: Tensor, result of minimum on the specified dim of input tensor,
it's data type is the same as input's Tensor.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -6101,7 +6119,7 @@ def reduce_min(input, dim=None, keep_dim=False, name=None): ...@@ -6101,7 +6119,7 @@ def reduce_min(input, dim=None, keep_dim=False, name=None):
# [[0.2, 0.3, 0.5, 0.9] # [[0.2, 0.3, 0.5, 0.9]
# [0.1, 0.2, 0.6, 0.7]] # [0.1, 0.2, 0.6, 0.7]]
# Each example is followed by the correspending output tensor. # Each example is followed by the correspending output tensor.
x = fluid.layers.data(name='x', shape=[4, 2], dtype='float32') x = fluid.data(name='x', shape=[2, 4], dtype='float32')
fluid.layers.reduce_min(x) # [0.1] fluid.layers.reduce_min(x) # [0.1]
fluid.layers.reduce_min(x, dim=0) # [0.1, 0.2, 0.5, 0.7] fluid.layers.reduce_min(x, dim=0) # [0.1, 0.2, 0.5, 0.7]
fluid.layers.reduce_min(x, dim=-1) # [0.2, 0.1] fluid.layers.reduce_min(x, dim=-1) # [0.2, 0.1]
...@@ -6111,7 +6129,7 @@ def reduce_min(input, dim=None, keep_dim=False, name=None): ...@@ -6111,7 +6129,7 @@ def reduce_min(input, dim=None, keep_dim=False, name=None):
# [[[1.0, 2.0], [3.0, 4.0]], # [[[1.0, 2.0], [3.0, 4.0]],
# [[5.0, 6.0], [7.0, 8.0]]] # [[5.0, 6.0], [7.0, 8.0]]]
# Each example is followed by the correspending output tensor. # Each example is followed by the correspending output tensor.
y = fluid.layers.data(name='y', shape=[2, 2, 2], dtype='float32') y = fluid.data(name='y', shape=[2, 2, 2], dtype='float32')
fluid.layers.reduce_min(y, dim=[1, 2]) # [1.0, 5.0] fluid.layers.reduce_min(y, dim=[1, 2]) # [1.0, 5.0]
fluid.layers.reduce_min(y, dim=[0, 1]) # [1.0, 2.0] fluid.layers.reduce_min(y, dim=[0, 1]) # [1.0, 2.0]
""" """
...@@ -6136,21 +6154,24 @@ def reduce_prod(input, dim=None, keep_dim=False, name=None): ...@@ -6136,21 +6154,24 @@ def reduce_prod(input, dim=None, keep_dim=False, name=None):
Computes the product of tensor elements over the given dimension. Computes the product of tensor elements over the given dimension.
Args: Args:
input (Variable): The input variable which is a Tensor or LoDTensor. input (Variable): The input variable which is a Tensor, the data type is float32,
dim (list|int|None): The dimensions along which the product is performed. If float64, int32, int64.
dim (list|int, optional): The dimensions along which the product is performed. If
:attr:`None`, multipy all elements of :attr:`input` and return a :attr:`None`, multipy all elements of :attr:`input` and return a
Tensor variable with a single element, otherwise must be in the Tensor variable with a single element, otherwise must be in the
range :math:`[-rank(input), rank(input))`. If :math:`dim[i] < 0`, range :math:`[-rank(input), rank(input))`. If :math:`dim[i] < 0`,
the dimension to reduce is :math:`rank + dim[i]`. the dimension to reduce is :math:`rank + dim[i]`.
keep_dim (bool|False): Whether to reserve the reduced dimension in the keep_dim (bool, optional): Whether to reserve the reduced dimension in the
output Tensor. The result tensor will have one fewer dimension output Tensor. The result tensor will have one fewer dimension
than the :attr:`input` unless :attr:`keep_dim` is true. than the :attr:`input` unless :attr:`keep_dim` is true, default
name(str|None): A name for this layer(optional). If set None, the value is False.
layer will be named automatically. name(str, optional): The default value is None. Normally there is no need for
user to set this property. For more information, please refer to :ref:`api_guide_Name`
Returns: Returns:
Variable: The reduced Tensor variable. Variable: Tensor, result of product on the specified dim of input tensor,
it's data type is the same as input's Tensor.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -6159,7 +6180,7 @@ def reduce_prod(input, dim=None, keep_dim=False, name=None): ...@@ -6159,7 +6180,7 @@ def reduce_prod(input, dim=None, keep_dim=False, name=None):
# [[0.2, 0.3, 0.5, 0.9] # [[0.2, 0.3, 0.5, 0.9]
# [0.1, 0.2, 0.6, 0.7]] # [0.1, 0.2, 0.6, 0.7]]
# Each example is followed by the correspending output tensor. # Each example is followed by the correspending output tensor.
x = fluid.layers.data(name='x', shape=[4, 2], dtype='float32') x = fluid.data(name='x', shape=[2, 4], dtype='float32')
fluid.layers.reduce_prod(x) # [0.0002268] fluid.layers.reduce_prod(x) # [0.0002268]
fluid.layers.reduce_prod(x, dim=0) # [0.02, 0.06, 0.3, 0.63] fluid.layers.reduce_prod(x, dim=0) # [0.02, 0.06, 0.3, 0.63]
fluid.layers.reduce_prod(x, dim=-1) # [0.027, 0.0084] fluid.layers.reduce_prod(x, dim=-1) # [0.027, 0.0084]
...@@ -6170,7 +6191,7 @@ def reduce_prod(input, dim=None, keep_dim=False, name=None): ...@@ -6170,7 +6191,7 @@ def reduce_prod(input, dim=None, keep_dim=False, name=None):
# [[[1.0, 2.0], [3.0, 4.0]], # [[[1.0, 2.0], [3.0, 4.0]],
# [[5.0, 6.0], [7.0, 8.0]]] # [[5.0, 6.0], [7.0, 8.0]]]
# Each example is followed by the correspending output tensor. # Each example is followed by the correspending output tensor.
y = fluid.layers.data(name='y', shape=[2, 2, 2], dtype='float32') y = fluid.data(name='y', shape=[2, 2, 2], dtype='float32')
fluid.layers.reduce_prod(y, dim=[1, 2]) # [24.0, 1680.0] fluid.layers.reduce_prod(y, dim=[1, 2]) # [24.0, 1680.0]
fluid.layers.reduce_prod(y, dim=[0, 1]) # [105.0, 384.0] fluid.layers.reduce_prod(y, dim=[0, 1]) # [105.0, 384.0]
""" """
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册