日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時間:2025/3/20 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 pytorch torch.Tensor.new_ones()(返回一个与size大小相同的用1填充的张量。 默认返回的Tensor具有与此张量相同的torch.dtype和torch.device) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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. 一個列表,元組或定義輸出張量形狀的整數(shù)的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. 返回張量的所需設(shè)備。 默認值:如果為None,則與此張量相同的torch.device。requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False. 如果自動求導(dǎo)應(yīng)該在返回的張量上記錄操作。 默認值:False

Example:

>>> tensor = torch.tensor((), dtype=torch.int32) >>> tensor.new_ones((2, 3)) tensor([[ 1, 1, 1],[ 1, 1, 1]], dtype=torch.int32)

總結(jié)

以上是生活随笔為你收集整理的pytorch torch.Tensor.new_ones()(返回一个与size大小相同的用1填充的张量。 默认返回的Tensor具有与此张量相同的torch.dtype和torch.device)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。