Returns a Tensor filled with random values sampled from a standard normal distribution with mean 0 and standard deviation 1, with ``shape`` and ``dtype``. Args: shape (tuple|list|Tensor): Shape of the Tensor to be created. The data type is ``int32`` or ``int64`` .
(
shape: ShapeLike,
dtype: DTypeLike | None = None,
name: str | None = None,
*,
out: paddle.Tensor | None = None,
device: PlaceLike | None = None,
requires_grad: bool = False,
)
| 806 | |
| 807 | |
| 808 | def standard_normal( |
| 809 | shape: ShapeLike, |
| 810 | dtype: DTypeLike | None = None, |
| 811 | name: str | None = None, |
| 812 | *, |
| 813 | out: paddle.Tensor | None = None, |
| 814 | device: PlaceLike | None = None, |
| 815 | requires_grad: bool = False, |
| 816 | ) -> Tensor: |
| 817 | """ |
| 818 | Returns a Tensor filled with random values sampled from a standard |
| 819 | normal distribution with mean 0 and standard deviation 1, with ``shape`` |
| 820 | and ``dtype``. |
| 821 | |
| 822 | Args: |
| 823 | shape (tuple|list|Tensor): Shape of the Tensor to be created. The data type is ``int32`` or ``int64`` . |
| 824 | If ``shape`` is a list or tuple, each element of it should be integer or 0-D Tensor with shape []. |
| 825 | If ``shape`` is an Tensor, it should be an 1-D Tensor which represents a list. |
| 826 | dtype (str|np.dtype|paddle.dtype|None, optional): The data type of the output Tensor. |
| 827 | Supported data types: float16, bfloat16, float32, float64, complex64, complex128. |
| 828 | Default is None, use global default dtype (see ``get_default_dtype`` |
| 829 | for details). |
| 830 | name (str|None, optional): Name for the operation (optional, default is None). |
| 831 | For more information, please refer to :ref:`api_guide_Name`. |
| 832 | out(Tensor, optional): The output tensor. |
| 833 | device(PlaceLike|None, optional): The desired device of returned tensor. |
| 834 | if None, uses the current device for the default tensor type (see paddle.device.set_device()). |
| 835 | device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. Default: None. |
| 836 | requires_grad(bool, optional): If autograd should record operations on the returned tensor. Default: False. |
| 837 | |
| 838 | Returns: |
| 839 | Tensor, A Tensor filled with random values sampled from a standard |
| 840 | normal distribution with mean 0 and standard deviation 1, with |
| 841 | ``shape`` and ``dtype``. |
| 842 | |
| 843 | Examples: |
| 844 | .. code-block:: pycon |
| 845 | |
| 846 | >>> import paddle |
| 847 | |
| 848 | >>> # doctest: +SKIP("Random output") |
| 849 | >>> # example 1: attr shape is a list which doesn't contain Tensor. |
| 850 | >>> out1 = paddle.standard_normal(shape=[2, 3]) |
| 851 | >>> print(out1) |
| 852 | >>> # doctest: +SKIP("Random output") |
| 853 | Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True, |
| 854 | [[-0.33719197, -0.25688133, -0.42868865], |
| 855 | [-0.27804616, -0.25058213, -0.28209466]]) |
| 856 | >>> # doctest: -SKIP |
| 857 | |
| 858 | >>> # example 2: attr shape is a list which contains Tensor. |
| 859 | >>> dim1 = paddle.to_tensor(2, 'int64') |
| 860 | >>> dim2 = paddle.to_tensor(3, 'int32') |
| 861 | >>> out2 = paddle.standard_normal(shape=[dim1, dim2, 2]) |
| 862 | >>> print(out2) |
| 863 | >>> # doctest: +SKIP("Random output") |
| 864 | Tensor(shape=[2, 3, 2], dtype=float32, place=Place(cpu), stop_gradient=True, |
| 865 | [[[ 0.81888396, -0.64831746], |
no test coverage detected