gaussian_random

paddle.fluid.layers.gaussian_random(shape, mean=0.0, std=1.0, seed=0, dtype='float32')[source]

Generate a random tensor whose data is drawn from a Gaussian distribution.

Parameters
  • shape (Tuple[int] | List[int]) – Shape of the generated random tensor.

  • mean (float) – Mean of the random tensor, defaults to 0.0.

  • std (float) – Standard deviation of the random tensor, defaults to 1.0.

  • seed (int) – (int, default 0) Random seed of generator.0 means use system wide seed.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) – Output data type, float32 or float64.

Returns

Random tensor whose data is drawn from a Gaussian distribution, dtype: flaot32 or float64 as specified.

Return type

Variable

Examples

# declarative mode
import numpy as np
from paddle import fluid

x = fluid.layers.gaussian_random((2, 3), std=2., seed=10)

place = fluid.CPUPlace()
exe = fluid.Executor(place)
start = fluid.default_startup_program()
main = fluid.default_main_program()

exe.run(start)
x_np, = exe.run(main, feed={}, fetch_list=[x])

x_np
# array([[2.3060477, 2.676496 , 3.9911983],
#        [0.9990833, 2.8675377, 2.2279181]], dtype=float32)
# imperative mode
import numpy as np
from paddle import fluid
import paddle.fluid.dygraph as dg

place = fluid.CPUPlace()
with dg.guard(place) as g:
    x = fluid.layers.gaussian_random((2, 4), mean=2., dtype="float32", seed=10)
    x_np = x.numpy()
x_np
# array([[2.3060477 , 2.676496  , 3.9911983 , 0.9990833 ],
#        [2.8675377 , 2.2279181 , 0.79029655, 2.8447366 ]], dtype=float32)