randn¶

paddle. randn ( shape, dtype=None, name=None ) [source]

Returns a Tensor filled with random values sampled from a standard normal distribution with mean 0 and standard deviation 1, with `shape` and `dtype`.

Parameters
• 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.

• dtype (str|np.dtype, optional) – The data type of the output Tensor. Supported data types: float32, float64. Default is None, use global default dtype (see `get_default_dtype` for details).

• 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 standard normal distribution with mean 0 and standard deviation 1, with `shape` and `dtype`.

Return type

Tensor

Examples

```>>> import paddle

>>> # example 1: attr shape is a list which doesn't contain Tensor.
>>> print(out1)
>>>
[[-0.29270014, -0.02925120, -1.07807338],
[ 1.19966674, -0.46673676, -0.18050613]])
>>>

>>> # example 2: attr shape is a list which contains Tensor.
>>> out2 = paddle.randn(shape=[dim1, dim2, 2])
>>> print(out2)
>>>
Tensor(shape=[2, 3, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
[[[-0.26019713,  0.54994684],
[ 0.46403214, -1.41178775],
[-0.15682915, -0.26639181]],
[[ 0.01364388, -2.81676364],
[ 0.86996621,  0.07524570],
[ 0.21443737,  0.90938759]]])
>>>

>>> # example 3: attr shape is a Tensor, the data type must be int64 or int32.