当前位置: 首页 > 工具软件 > ONES > 使用案例 >

pytorch之torch.ones_like

申屠项明
2023-12-01

torch.ones_like(input, dtype=None, layout=None, device=None, requires_grad=False) → Tensor

返回一个填充了标量值1的张量,其大小与之相同 input。torch.ones_like(input)相当于 。torch.ones(input.size(), dtype=input.dtype, layout=input.layout, device=input.device)

Parameters:
input (Tensor) – the size of input will determine size of the output tensor
dtype (torch.dtype, optional) – the desired data type of returned Tensor. Default: if None, defaults to the dtype of input.
layout (torch.layout, optional) – the desired layout of returned tensor. Default: if None, defaults to the layout of input.
device (torch.device, optional) – the desired device of returned tensor. Default: if None, defaults to the device of input.
requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.

例子

input = torch.empty(2, 3)
torch.ones_like(input)
tensor([[ 1., 1., 1.],
[ 1., 1., 1.]])

 类似资料: