from https://pytorch.org/docs/1.1.0/tensors.html?highlight=new_ones#torch.Tensor.new_ones
new_ones(size, dtype=None, device=None, requires_grad=False) → Tensor
Returns a Tensor of size size filled with 1. By default, the returned Tensor has the same torch.dtype and torch.device as this tensor.
返回一个与size大小相同的用1填充的张量。
默认情况下,返回的Tensor具有与此张量相同的torch.dtype和torch.device。
Parameters
size (int...) – a list, tuple, or torch.Size of integers defining the shape of the output tensor.
一个列表,元组或定义输出张量形状的整数的torch.Size
dtype (torch.dtype, optional) – the desired type of returned tensor. Default: if None, same torch.dtype as this tensor.
所需的返回张量类型。
默认值:如果为None,则与此张量相同的torch.dtype。
device (torch.device, optional) – the desired device of returned tensor. Default: if None, same torch.device as this tensor.
返回张量的所需设备。
默认值:如果为None,则与此张量相同的torch.device。
requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.
如果自动求导应该在返回的张量上记录操作。 默认值:False。
Example:
>>> tensor = torch.tensor((), dtype=torch.int32)
>>> tensor.new_ones((2, 3))
tensor([[ 1, 1, 1],
[ 1, 1, 1]], dtype=torch.int32)