pytorch生成隨機tensor
torch.rand(*sizes, out=None)
torch.rand(*sizes, out=None) → Tensor
返回一個tensor,包含了[0,1)的均勻分佈中抽取的一組隨機數。
tensor的形狀由sizes定義。
代碼
x = torch.rand(5,3)
print(x)
結果
tensor([[0.7740, 0.0933, 0.9731],
[0.6337, 0.5646, 0.0586],
[0.8880, 0.0646, 0.9081],
[0.8464, 0.6537, 0.7927],
[0.4985, 0.7783, 0.1202]])
torch.randn(*sizes, out=None)
返回一個tensor,包含了從標準正太分佈(均值爲0,方差爲1,即高斯白噪聲)中抽取的一組隨機數。tensor的形狀由sizes定義。
代碼
x = torch.randn(5,3)
print(x)
結果
tensor([[-1.0065, 1.0913, 0.3004],
[ 0.0553, 0.7115, 1.5073],
[ 1.4142, 0.6983, 0.0543],
[ 0.8911, 0.9299, -0.3076],
[-0.2323, 0.4869, 1.4421]])