normal

paddle. normal ( mean=0.0, std=1.0, shape=None, name=None ) [source]

Returns a Tensor filled with random values sampled from a normal distribution with mean and std (standard deviation) .

If mean is a Tensor, the output Tensor has the same shape and data type as mean. If mean is not a Tensor and std is a Tensor, the output Tensor has the same shape and data type as std. If mean and std are not a Tensor, the output Tensor has the same shape as shape, with data type float32.

If mean and std are Tensor, the num of elements of mean and std should be the same.

Parameters
  • mean (float|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. If mean is a Tensor(data type supports float32, float64), it has per-element means. Default is 0.0

  • std (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. If std is a Tensor(data type supports float32, float64), it has per-element standard deviations. Default is 1.0

  • shape (tuple|list|Tensor) – Shape of the Tensor to be created. The data type is int32 or int64 . If shape is a list or tuple, each element of it should be integer or 0-D Tensor with shape []. If shape is an Tensor, it should be an 1-D Tensor which represents a list. If mean or std is a Tensor, the shape of the output Tensor is the same as mean or std , attr shape is ignored. Default is None

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

A Tensor filled with random values sampled from a normal distribution with mean and std .

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])
>>>