深入浅出Pytorch函数——torch.zeros_like

分类目录:《深入浅出Pytorch函数》总目录
相关文章:
· 深入浅出Pytorch函数——torch.Tensor
· 深入浅出Pytorch函数——torch.ones
· 深入浅出Pytorch函数——torch.zeros
· 深入浅出Pytorch函数——torch.full
· 深入浅出Pytorch函数——torch.ones_like
· 深入浅出Pytorch函数——torch.zeros_like
· 深入浅出Pytorch函数——torch.full_like


返回一个形状与input相同且值全为0的张量。torch.zeros_like(input)相当于torch.zeros(input.size, dtype=input.dtype,layout=input.layout,device=input.device)

语法

torch.zeros_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) → Tensor

参数

  • input:[Tensor] input向量的形状决定了输出向量的形状。
  • dtype:[可选,torch.dtype] 返回张量的所需数据类型。如果为None,则使用全局默认值(参考torch.set_default_tensor_type())。
  • layout:[可选,torch.layout] 返回张量的期望内存布局形式,默认为torch.strided
  • device:返回张量的期望计算设备。如果为None,使用当前的设备(参考torch.set_default_tensor_type()),设备将CPU用于CPU张量类型,将CUDA设备用于CUDA张量类型。
  • requires_grad:[可选,bool] 是否需要自动微分,默认为False
  • memory_format:[可选,torch.memory_format] 返回张量的所需内存格式,默认为torch.preserve_format

返回值

返回一个形状与input相同且值全为0的张量。

实例

>>> input = torch.empty(2, 3)
>>> torch.zeros_like(input)
tensor([[ 0.,  0.,  0.],
        [ 0.,  0.,  0.]])

猜你喜欢

转载自blog.csdn.net/hy592070616/article/details/129599384