@ -5889,21 +5889,27 @@ def reduce_sum(input, dim=None, keep_dim=False, name=None):
Computes the sum of tensor elements over the given dimension .
Args :
input ( Variable ) : The input variable which is a Tensor or LoDTensor .
dim ( list | int | None ) : The dimensions along which the sum is performed . If
input ( Variable ) : The input variable which is a Tensor , the data type is float32 ,
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
Tensor variable with a single element , 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 ] ` .
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
than the : attr : ` input ` unless : attr : ` keep_dim ` is true .
name ( str | None ) : A name for this layer ( optional ) . If set None , the layer
will be named automatically .
than the : attr : ` input ` unless : attr : ` keep_dim ` is true , default
value is False .
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 :
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 :
. . code - block : : python
@ -5912,7 +5918,7 @@ def reduce_sum(input, dim=None, keep_dim=False, name=None):
# [[0.2, 0.3, 0.5, 0.9]
# [0.1, 0.2, 0.6, 0.7]]
# 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 , dim = 0 ) # [0.3, 0.5, 1.1, 1.6]
fluid . layers . reduce_sum ( x , dim = - 1 ) # [1.9, 1.6]
@ -5922,7 +5928,7 @@ def reduce_sum(input, dim=None, keep_dim=False, name=None):
# [[[1, 2], [3, 4]],
# [[5, 6], [7, 8]]]
# 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 = [ 0 , 1 ] ) # [16, 20]
@ -5957,22 +5963,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.
Args :
input ( Variable ) : The input variable which is a Tensor or LoDTensor .
dim ( list | int | None ) : The dimension along which the mean is computed . If
input ( Variable ) : The input variable which is a Tensor , the data type is float32 ,
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 `
and return a variable with a single element , otherwise it
must be in the range : math : ` [ - rank ( input ) , rank ( input ) ) ` . If
: math : ` dim [ i ] < 0 ` , the dimension to reduce is
: 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
than the : attr : ` input ` unless : attr : ` keep_dim ` is true .
name ( str | None ) : A name for this layer ( optional ) . If set ` None ` , the layer
will be named automatically .
than the : attr : ` input ` unless : attr : ` keep_dim ` is true , default
value is False .
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 :
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 :
. . code - block : : python
@ -5981,7 +5993,7 @@ def reduce_mean(input, dim=None, keep_dim=False, name=None):
# [[0.2, 0.3, 0.5, 0.9]
# [0.1, 0.2, 0.6, 0.7]]
# 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 , dim = 0 ) # [0.15, 0.25, 0.55, 0.8]
fluid . layers . reduce_mean ( x , dim = - 1 ) # [0.475, 0.4]
@ -5991,7 +6003,7 @@ def reduce_mean(input, dim=None, keep_dim=False, name=None):
# [[[1.0, 2.0], [3.0, 4.0]],
# [[5.0, 6.0], [7.0, 8.0]]]
# 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 = [ 0 , 1 ] ) # [4.0, 5.0]
"""
@ -6025,20 +6037,23 @@ def reduce_max(input, dim=None, keep_dim=False, name=None):
Computes the maximum of tensor elements over the given dimension .
Args :
input ( Variable ) : The input variable which is a Tensor or LoDTensor .
dim ( list | int | None ) : The dimension along which the maximum is computed .
input ( Variable ) : The input variable which is a Tensor , the data type is float32 ,
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
: attr : ` input ` and return a Tensor variable with a single element ,
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 ] ` .
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
than the : attr : ` input ` unless : attr : ` keep_dim ` is true .
name ( str | None ) : A name for this layer ( optional ) . If set None , the layer
will be named automatically .
than the : attr : ` input ` unless : attr : ` keep_dim ` is true , default
value is False .
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 :
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 :
. . code - block : : python
@ -6048,7 +6063,7 @@ def reduce_max(input, dim=None, keep_dim=False, name=None):
# [[0.2, 0.3, 0.5, 0.9]
# [0.1, 0.2, 0.6, 0.7]]
# 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 , dim = 0 ) # [0.2, 0.3, 0.6, 0.9]
fluid . layers . reduce_max ( x , dim = - 1 ) # [0.9, 0.7]
@ -6058,7 +6073,7 @@ def reduce_max(input, dim=None, keep_dim=False, name=None):
# [[[1.0, 2.0], [3.0, 4.0]],
# [[5.0, 6.0], [7.0, 8.0]]]
# 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 = [ 0 , 1 ] ) # [7.0, 8.0]
"""
@ -6083,20 +6098,23 @@ def reduce_min(input, dim=None, keep_dim=False, name=None):
Computes the minimum of tensor elements over the given dimension .
Args :
input ( Variable ) : The input variable which is a Tensor or LoDTensor .
dim ( list | int | None ) : The dimensions along which the minimum is computed .
input ( Variable ) : The input variable which is a Tensor , the data type is float32 ,
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
: attr : ` input ` and return a Tensor variable with a single element ,
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 ] ` .
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
than the : attr : ` input ` unless : attr : ` keep_dim ` is true .
name ( str | None ) : A name for this layer ( optional ) . If set None , the layer
will be named automatically .
than the : attr : ` input ` unless : attr : ` keep_dim ` is true , default
value is False .
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 :
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 :
. . code - block : : python
@ -6106,7 +6124,7 @@ def reduce_min(input, dim=None, keep_dim=False, name=None):
# [[0.2, 0.3, 0.5, 0.9]
# [0.1, 0.2, 0.6, 0.7]]
# 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 , dim = 0 ) # [0.1, 0.2, 0.5, 0.7]
fluid . layers . reduce_min ( x , dim = - 1 ) # [0.2, 0.1]
@ -6116,7 +6134,7 @@ def reduce_min(input, dim=None, keep_dim=False, name=None):
# [[[1.0, 2.0], [3.0, 4.0]],
# [[5.0, 6.0], [7.0, 8.0]]]
# 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 = [ 0 , 1 ] ) # [1.0, 2.0]
"""
@ -6141,21 +6159,24 @@ def reduce_prod(input, dim=None, keep_dim=False, name=None):
Computes the product of tensor elements over the given dimension .
Args :
input ( Variable ) : The input variable which is a Tensor or LoDTensor .
dim ( list | int | None ) : The dimensions along which the product is performed . If
input ( Variable ) : The input variable which is a Tensor , the data type is float32 ,
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
Tensor variable with a single element , 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 ] ` .
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
than the : attr : ` input ` unless : attr : ` keep_dim ` is true .
name ( str | None ) : A name for this layer ( optional ) . If set None , the
layer will be named automatically .
than the : attr : ` input ` unless : attr : ` keep_dim ` is true , default
value is False .
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 :
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 :
. . code - block : : python
@ -6164,7 +6185,7 @@ def reduce_prod(input, dim=None, keep_dim=False, name=None):
# [[0.2, 0.3, 0.5, 0.9]
# [0.1, 0.2, 0.6, 0.7]]
# 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 , dim = 0 ) # [0.02, 0.06, 0.3, 0.63]
fluid . layers . reduce_prod ( x , dim = - 1 ) # [0.027, 0.0084]
@ -6175,7 +6196,7 @@ def reduce_prod(input, dim=None, keep_dim=False, name=None):
# [[[1.0, 2.0], [3.0, 4.0]],
# [[5.0, 6.0], [7.0, 8.0]]]
# 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 = [ 0 , 1 ] ) # [105.0, 384.0]
"""