PyTorch torch.randn_like Function


Pytorch torch 参考手册Pytorch torch Reference Manual

torch.randn_likeIt is a function in PyTorch used to create a random tensor with standard normal distribution and the same shape as the input tensor.

Function Definition

torch.randn_like(input, dtype=None, device=None, requires_grad=False)

Usage Example

Example

import torch

# Create an input tensor
input = torch.tensor([[1, 2], [3, 4]])

# Create a standard normal distribution random tensor with the same shape as the input
x = torch.randn_like(input)

print(x)

Pytorch torch 参考手册Pytorch torch Reference Manual

Other Extensions