normal¶
- paddle. normal ( mean: complex | Tensor = 0.0, std: float | Tensor = 1.0, shape: ShapeLike | None = None, name: str | None = None ) Tensor [source]
-
Returns a Tensor filled with random values sampled from a normal distribution with
mean
andstd
(standard deviation) .If
mean
is a Tensor, the output Tensor has the same shape and data type asmean
. Ifmean
is not a Tensor andstd
is a Tensor, the output Tensor has the same shape and data type asstd
. Ifmean
andstd
are not a Tensor, the output Tensor has the same shape asshape
, with data type float32.If
mean
andstd
are Tensor, the num of elements ofmean
andstd
should be the same.If
mean
is a complex number, the output Tensor follows complex normal distribution, with data type complex 64. Ifmean
is a Tensor with complex data type, the output Tensor has same data type withmean
.- Parameters
-
mean (float|complex|Tensor, optional) – The mean of the output Tensor’s normal distribution. If
mean
is float, all elements of the output Tensor shared the same mean. Ifmean
is a Tensor(data type supports float32, float64, complex64, complex128), it has per-element means. Default is 0.0std (float|Tensor, optional) – The standard deviation of the output Tensor’s normal distribution. If
std
is float, all elements of the output Tensor shared the same standard deviation. Ifstd
is a Tensor(data type supports float32, float64), it has per-element standard deviations. Default is 1.0shape (tuple|list|Tensor|None, optional) – Shape of the Tensor to be created. The data type is
int32
orint64
. Ifshape
is a list or tuple, each element of it should be integer or 0-D Tensor with shape []. Ifshape
is an Tensor, it should be an 1-D Tensor which represents a list. Ifmean
orstd
is a Tensor, the shape of the output Tensor is the same asmean
orstd
, attrshape
is ignored. Default is Nonename (str|None, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.
- Returns
-
Tensor, A Tensor filled with random values sampled from a normal distribution with
mean
andstd
.
Examples
>>> import paddle >>> out1 = paddle.normal(shape=[2, 3]) >>> print(out1) >>> Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True, [[-0.85107994, -0.85490644, -1.35941815], [-0.55500370, 0.20964541, 2.24193954]]) >>> >>> mean_tensor = paddle.to_tensor([1.0, 2.0, 3.0]) >>> out2 = paddle.normal(mean=mean_tensor) >>> print(out2) >>> Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True, [1.05411839, 3.71514320, 3.42665267]) >>> >>> std_tensor = paddle.to_tensor([1.0, 2.0, 3.0]) >>> out3 = paddle.normal(mean=mean_tensor, std=std_tensor) >>> print(out3) >>> Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True, [0.48646951, 0.00815189, 3.74022293]) >>> >>> paddle.seed(200) >>> out4 = paddle.normal(mean=1+1j, shape=[2, 3]) >>> print(out4) Tensor(shape=[2, 3], dtype=complex64, place=Place(cpu), stop_gradient=True, [[(1.137553095817566+1.0932074785232544j) , (1.7955012321472168+0.5819810628890991j) , (0.32699793577194214+0.9083631038665771j)], [(1.1745303869247437+0.09971672296524048j), (1.1627092361450195-0.30863022804260254j), (1.9428746700286865+1.0686945915222168j) ]]) >>> mean_tensor = paddle.to_tensor([1+1j, 2+2j, 3+3j]) >>> out5 = paddle.normal(mean=mean_tensor) >>> print(out5) Tensor(shape=[3], dtype=complex64, place=Place(cpu), stop_gradient=True, [(1.136009693145752-0.11074113845825195j), (2.529331684112549+2.1968750953674316j) , (2.2910101413726807+1.8114780187606812j)])