参考链接: fill_(value) → Tensor
实验代码展示:
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
>>> torch.manual_seed(seed=20200910)
<torch._C.Generator object at 0x00000247C745D330>
>>>
>>> a = torch.randn(3,4)
>>> a
tensor([[ 0.2824, -0.3715, 0.9088, -1.7601],
[-0.1806, 2.0937, 1.0406, -1.7651],
[ 1.1216, 0.8440, 0.1783, 0.6859]])
>>> a.fill_(2020.0910)
tensor([[2020.0909, 2020.0909, 2020.0909, 2020.0909],
[2020.0909, 2020.0909, 2020.0909, 2020.0909],
[2020.0909, 2020.0909, 2020.0909, 2020.0909]])
>>> a
tensor([[2020.0909, 2020.0909, 2020.0909, 2020.0909],
[2020.0909, 2020.0909, 2020.0909, 2020.0909],
[2020.0909, 2020.0909, 2020.0909, 2020.0909]])
>>> a[0,0]
tensor(2020.0909)
>>> a[0,0].item()
2020.0909423828125
>>>
>>>