0
点赞
收藏
分享

微信扫一扫

torch.zeros_like()和torch.ones_like()简要介绍

定义

  • torch.zeros_like(input)
  • torch.ones_like(input)

用法

分别生成和输入数据维度一致的全为0或全为1的内容

示例

import torch

a = torch.tensor([[1,2,3],[4,5,6]])

print(torch.zeros_like(a))
print(torch.ones_like(a))

>>>tensor([[0, 0, 0],
           [0, 0, 0]])
   tensor([[1, 1, 1],
           [1, 1, 1]])
举报

相关推荐

0 条评论