randn_like
- paddle. randn_like ( x: Tensor, dtype: DTypeLike | None = None, name: str | None = None ) Tensor [source]
-
Returns a tensor with the same size as input that is filled with random numbers from a normal distribution with mean 0 and variance 1.
- Parameters :
-
x (Tensor) – The input multi-dimensional tensor which specifies shape. The dtype of
x
can be float16, bfloat16, float32, float64, complex64, complex128.dtype (str|np.dtype|paddle.dtype|None, optional) – The data type of the output tensor. Supported data types: float16, bfloat16, float32, float64, complex64, complex128. If
dtype
is None, the data type is the same as x’s data type. Default is None.name (str|None, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.
- Returns :
-
Tensor, A Tensor with the same size as input that is filled with random numbers from a normal distribution with mean 0 and variance 1.
Examples
>>> import paddle >>> # example 1: >>> # dtype is None and the dtype of x is float32 >>> x = paddle.zeros((1,2)).astype("float32") >>> out1 = paddle.randn_like(x) >>> print(out1) >>> Tensor(shape=[1, 2], dtype=float32, place=Place(cpu), stop_gradient=True, [[ 0.51785558, -0.10632933]]) >>> >>> print(out1.dtype) paddle.float32 >>> # example 2: >>> # dtype is None and the dtype of x is float64 >>> x = paddle.zeros((1,2)).astype("float64") >>> out2 = paddle.randn_like(x) >>> print(out2) >>> Tensor(shape=[1, 2], dtype=float64, place=Place(cpu), stop_gradient=True, [[ 0.64437317, -1.26898670]]) >>> >>> print(out2.dtype) paddle.float64 >>> # example 3: >>> # dtype is float64 and the dtype of x is float32 >>> x = paddle.zeros((1,2)).astype("float32") >>> out3 = paddle.randn_like(x, dtype="float64") >>> print(out3) >>> Tensor(shape=[1, 2], dtype=float64, place=Place(cpu), stop_gradient=True, [[ 1.45264642, -1.33133914]]) >>> >>> print(out3.dtype) paddle.float64