normal
- paddle. normal ( mean: complex | Tensor = 0.0, std: float | Tensor = 1.0, shape: ShapeLike | None = None, name: str | None = None, *, out: Tensor | None = None ) Tensor [source]
-
Returns a Tensor filled with random values sampled from a normal distribution with
meanandstd(standard deviation).If
meanis a Tensor, the output Tensor has the same shape and data type asmean. Ifmeanis not a Tensor andstdis a Tensor, the output Tensor has the same shape and data type asstd. Ifmeanandstdare not a Tensor, the output Tensor has the same shape asshape, with data type float32.If
meanandstdare Tensor, the num of elements ofmeanandstdshould be the same.If
meanis a complex number, the output Tensor follows complex normal distribution, with data type complex64. Ifmeanis a Tensor with complex data type, the output Tensor has same data type withmean.Note
Alias Support: The parameter name
sizecan be used as an alias forshape. For example,normal(size=[2, 3], ...)is equivalent tonormal(shape=[2, 3], ...).- Parameters
-
mean (float|complex|Tensor, optional) – The mean of the output Tensor’s normal distribution. If
meanis float, all elements of the output Tensor shared the same mean. Ifmeanis 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
stdis float, all elements of the output Tensor shared the same standard deviation. Ifstdis 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
int32orint64. Ifshapeis a list or tuple, each element of it should be integer or 0-D Tensor with shape []. Ifshapeis an Tensor, it should be an 1-D Tensor which represents a list. Ifmeanorstdis a Tensor, the shape of the output Tensor is the same asmeanorstd, attrshapeis ignored. Default is Nonename (str|None, optional) – Name for the operation (optional, default is None). For more information, please refer to api_guide_Name.
out (Tensor|None, optional) – Optional output tensor. If provided, the result will be stored in this tensor. The
outtensor must have the same shape and dtype as the expected output. Default is None.
- Returns
-
A Tensor filled with random values sampled from a normal distribution with
meanandstd. - Return type
-
Tensor
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.13755310+1.09320748j), (1.79550123+0.58198106j), (0.32699794+0.90836310j)], [(1.17453039+0.09971672j), (1.16270924-0.30863023j), (1.94287467+1.06869459j)]]) >>> 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.13600969-0.11074114j), (2.52933168+2.19687510j), (2.29101014+1.81147802j)])
