参考链接: torch.empty(*size, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False) → Tensor
参考链接: random_(from=0, to=None, *, generator=None) → Tensor
函数使用说明:
torch.empty(*size, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False, pin_memory=False)
根据给定形状和类型,返回一个包含未经初始化数据的张量.
函数使用说明:
random_(from=0, to=None, *, generator=None) → Tensor
用一个离散均匀分布[from, to - 1]来填充当前自身张量.
代码实验展示:
Microsoft Windows [版本 10.0.18363.1256]
(c) 2019 Microsoft Corporation。保留所有权利。
C:\Users\chenxuqi>conda activate ssd4pytorch1_2_0
(ssd4pytorch1_2_0) C:\Users\chenxuqi>python
Python 3.7.7 (default, May 6 2020, 11:45:54) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> input = torch.empty(2, 3)
>>> input
tensor([[0., 0., 0.],
[0., 0., 0.]])
>>> input = torch.empty(2, 3)
>>> input
tensor([[0., 0., 0.],
[0., 0., 0.]])
>>> torch.empty(2, 3)
tensor([[0., 0., 0.],
[0., 0., 0.]])
>>> torch.empty(2, 3)
tensor([[0.0000e+00, 0.0000e+00, 8.4078e-45],
[0.0000e+00, 1.4013e-45, 0.0000e+00]])
>>> torch.empty(2, 3)
tensor([[0., 0., 0.],
[0., 0., 0.]])
>>> torch.empty(2, 3)
tensor([[0.0000e+00, 0.0000e+00, 8.4078e-45],
[0.0000e+00, 1.4013e-45, 0.0000e+00]])
>>>
>>>
>>>
>>>
>>> torch.manual_seed(seed=20200910)
<torch._C.Generator object at 0x00000211B490D330>
>>>
>>> output = input.random_(0, to=10)
>>> output
tensor([[3., 8., 4.],
[7., 8., 5.]])
>>> input
tensor([[3., 8., 4.],
[7., 8., 5.]])
>>>
>>> input.random_(0, to=10)
tensor([[0., 8., 8.],
[1., 6., 4.]])
>>> input.random_(0, to=10)
tensor([[2., 7., 9.],
[0., 5., 0.]])
>>> input.random_(0, to=10)
tensor([[9., 9., 2.],
[0., 4., 2.]])
>>>
>>>
>>>