standard_normal¶
- paddle. standard_normal ( shape: ShapeLike, dtype: DTypeLike | None = None, name: str | None = None ) Tensor [source]
-
Returns a Tensor filled with random values sampled from a standard normal distribution with mean 0 and standard deviation 1, with
shape
anddtype
.- Parameters
-
shape (tuple|list|Tensor) – 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.dtype (str|np.dtype|paddle.dtype|None, optional) – The data type of the output Tensor. Supported data types: float32, float64, complex64, complex128. Default is None, use global default dtype (see
get_default_dtype
for details).name (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 standard
-
normal distribution with mean 0 and standard deviation 1, with
shape
anddtype
.
Examples
>>> import paddle >>> >>> # example 1: attr shape is a list which doesn't contain Tensor. >>> out1 = paddle.standard_normal(shape=[2, 3]) >>> print(out1) >>> Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True, [[-0.33719197, -0.25688133, -0.42868865], [-0.27804616, -0.25058213, -0.28209466]]) >>> >>> # example 2: attr shape is a list which contains Tensor. >>> dim1 = paddle.to_tensor(2, 'int64') >>> dim2 = paddle.to_tensor(3, 'int32') >>> out2 = paddle.standard_normal(shape=[dim1, dim2, 2]) >>> print(out2) >>> Tensor(shape=[2, 3, 2], dtype=float32, place=Place(cpu), stop_gradient=True, [[[ 0.81888396, -0.64831746], [ 1.28911388, -1.88154876], [-0.03271919, -0.32410008]], [[-0.20224631, 0.46683890], [ 1.91947734, 0.71657443], [ 0.33410960, -0.64256823]]]) >>> >>> # example 3: attr shape is a Tensor, the data type must be int64 or int32. >>> shape_tensor = paddle.to_tensor([2, 3]) >>> out3 = paddle.standard_normal(shape_tensor) >>> print(out3) >>> Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True, [[ 0.01182475, -0.44895259, -1.79227340], [ 1.52022707, -0.83830303, 0.05261501]]) >>> >>> # example 4: attr dtype is complex64. >>> paddle.seed(200) >>> shape_tensor = paddle.to_tensor([2, 3]) >>> out4 = paddle.standard_normal(shape_tensor, dtype='complex64') >>> print(out4) Tensor(shape=[2, 3], dtype=complex64, place=Place(cpu), stop_gradient=True, [[ (0.1375531256198883+0.0932074561715126j) , (0.7955012917518616-0.41801896691322327j), (-0.6730020642280579-0.09163688868284225j)], [ (0.17453041672706604-0.9002832770347595j), (0.16270922124385834-1.3086302280426025j), (0.9428746104240417+0.06869460642337799j)]])