torch.Tensor.fill_(value) method

Reprinted from: https://blog.csdn.net/m0_46653437/article/details/112495682
Insert picture description here
Fill all values ​​in tensor with the specified value

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 0x000001FB002DD330>
>>> a = torch.randn(3,4)
>>> b = a
>>> 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]])
>>> b
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_(20200910.0)
tensor([[20200910., 20200910., 20200910., 20200910.],
        [20200910., 20200910., 20200910., 20200910.],
        [20200910., 20200910., 20200910., 20200910.]])
>>> a
tensor([[20200910., 20200910., 20200910., 20200910.],
        [20200910., 20200910., 20200910., 20200910.],
        [20200910., 20200910., 20200910., 20200910.]])
>>> b
tensor([[20200910., 20200910., 20200910., 20200910.],
        [20200910., 20200910., 20200910., 20200910.],
        [20200910., 20200910., 20200910., 20200910.]])

Guess you like

Origin blog.csdn.net/qq_35037684/article/details/113769542