pytorch torch.Tensor.new_ones()(返回一个与size大小相同的用1填充的张量。 默认返回的Tensor具有与此张量相同的torch.dtype和torch.device)

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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Dontla

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值