torch.zeros_like

2022-09-02 13:31:49 浏览数 (1)

torch.zeros_like:生成和括号内变量维度维度一致的全是零的内容。

代码语言:javascript复制
import torch
a = torch.rand(5,1)
print(a)
n=torch.zeros_like(a)
print('n=',n)

tensor([[0.9653],
            [0.5581],
            [0.1648],
            [0.3715],
            [0.2194]])
n= tensor([[0.],
            [0.],
            [0.],
            [0.],
            [0.]])

0 人点赞