pytorch torch.Tensor.new_ones()(返回一个与size大小相同的用1填充的张量。 默认返回的Tensor具有与此张量相同的torch.dtype和torch.device)
生活随笔
收集整理的這篇文章主要介紹了
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.Sizedtype (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)總結
以上是生活随笔為你收集整理的pytorch torch.Tensor.new_ones()(返回一个与size大小相同的用1填充的张量。 默认返回的Tensor具有与此张量相同的torch.dtype和torch.device)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 英语网络聊天中的一些习惯性缩写
- 下一篇: pytorch torch.device