uniform_random_batch_size_like

paddle.fluid.layers.nn. uniform_random_batch_size_like ( input, shape, dtype='float32', input_dim_idx=0, output_dim_idx=0, min=- 1.0, max=1.0, seed=0 ) [source]

Warning: API “paddle.fluid.layers.nn.uniform_random_batch_size_like” is deprecated since 1.8.0, and will be removed in future versions. Please use “paddle.uniform” instead.

This OP initializes a variable with random values sampled from a uniform distribution in the range [min, max). The input_dim_idx used to get the input dimension value which will be used to resize the output dimension.

 *Case 1:

     Given:
         input =[[0.946741  , 0.1357001 , 0.38086128]]    # input.shape=[1,3]
         shape=[2,4]

     result.shape[output_dim_idx] = input.shape[input_dim_idx],
     output_dim_idx = 0,
     input_dim_idx = 0,
     result.shape[0] = input.shape[0],
     then:
         result=[[ 0.3443427 , -0.23056602,  0.3477049 ,  0.06139076]]    # result.shape=[1,4]

*Case 2:

    Given:
        input =[[0.946741  , 0.1357001 , 0.38086128]]     # input.shape=[1,3]
        shape=[2,4]
        input_dim_idx=1
        output_dim_idx=1

    result.shape[output_dim_idx] = input.shape[input_dim_idx],
    output_dim_idx = 1,
    input_dim_idx = 1,
    result.shape[1] = input.shape[1],
    then:
        result=[[-0.23133647, -0.84195036,  0.21441269],
                [-0.08774924,  0.25605237, -0.09403259]]    # result.shape=[2,3]

System Message: WARNING/2 (/usr/local/lib/python3.8/site-packages/paddle/fluid/layers/nn.py:docstring of paddle.fluid.layers.nn.uniform_random_batch_size_like, line 36)

Explicit markup ends without a blank line; unexpected unindent.

Args:

input (Variable): A Tensor. Supported data types: float32, float64. shape (tuple|list): A python list or python tuple. The shape of the output Tensor, the data type is int. input_dim_idx (int, optional): An index used to get the input dimension value which will be used to resize the output dimension. Default 0. output_dim_idx (int, optional): An index used to indicate the specific dimension that will be replaced by corresponding input dimension value. Default 0. min (float, optional): The lower bound on the range of random values to generate, the min is included in the range. Default -1.0. max (float, optional): The upper bound on the range of random values to generate, the max is excluded in the range. Default 1.0. seed (int, optional): Random seed used for generating samples. 0 means use a seed generated by the system.Note that if seed is not 0, this operator will always generate the same random numbers every time. dtype(np.dtype|core.VarDesc.VarType|str, optional): The data type of output Tensor. Supported data types: float32, float64. Default float32.

Returns:

Variable: A Tensor of the specified shape filled with uniform_random values. The shape of the Tensor is determined by the shape parameter and the specified dimension of the input Tensor.

Examples:
import paddle.fluid as fluid

# example 1:
input = fluid.data(name="input", shape=[1, 3], dtype='float32')
out_1 = fluid.layers.uniform_random_batch_size_like(input, [2, 4]) # out_1.shape=[1, 4]

# example 2:
out_2 = fluid.layers.uniform_random_batch_size_like(input, [2, 4], input_dim_idx=1, output_dim_idx=1) # out_2.shape=[2, 3]