我正在经历pytorch
教程并遇到了pytorch.empty
功能。有人提到空可以用于未初始化的数据。但是,当我打印它时,我得到了一个值。这和有什么区别pytorch.rand
它还生成数据(我知道 rand 生成 0 到 1 之间的值)。下面是我尝试过的代码
a = torch.empty(3,4)
print(a)
Output:
tensor([[ 8.4135e-38, 0.0000e+00, 6.2579e-41, 5.4592e-39],
[-5.6345e-08, 2.5353e+30, 5.0447e-44, 1.7020e-41],
[ 1.4000e-38, 5.7697e-05, 2.5353e+30, 2.1580e-43]])
b = torch.rand(3,4)
print(b)
Output:
tensor([[ 0.1514, 0.8406, 0.2708, 0.3422],
[ 0.7196, 0.6120, 0.4476, 0.6705],
[ 0.6989, 0.2086, 0.5100, 0.8285]])
这是官方文档的链接 https://pytorch.org/docs/stable/torch.html#torch.empty