分類目錄:《深入淺出Pytorch函數(shù)》總目錄
相關(guān)文章:
· 深入淺出Pytorch函數(shù)——torch.Tensor
· 深入淺出Pytorch函數(shù)——torch.ones
· 深入淺出Pytorch函數(shù)——torch.zeros
· 深入淺出Pytorch函數(shù)——torch.full
· 深入淺出Pytorch函數(shù)——torch.ones_like
· 深入淺出Pytorch函數(shù)——torch.zeros_like
· 深入淺出Pytorch函數(shù)——torch.full_like文章來源:http://www.zghlxwxcb.cn/news/detail-425599.html
語法
torch.ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor
參數(shù)
-
size
:大小,定義輸出張量形狀的整數(shù)序列。可以是可變數(shù)量的參數(shù)或集合,如:列表或元組。 -
out
:[可選,Tensor] 輸出張量 -
dtype
:[可選,torch.dtype
] 返回張量的所需數(shù)據(jù)類型。如果為None
,則使用全局默認(rèn)值(參考torch.set_default_tensor_type()
)。 -
layout
:[可選,torch.layout
] 返回張量的期望內(nèi)存布局形式,默認(rèn)為torch.strided
。 -
device
:返回張量的期望計(jì)算設(shè)備。如果為None
,使用當(dāng)前的設(shè)備(參考torch.set_default_tensor_type()
),設(shè)備將CPU用于CPU張量類型,將CUDA設(shè)備用于CUDA張量類型。 -
requires_grad
:[可選,bool
] 是否需要自動(dòng)微分,默認(rèn)為False
。
返回值
返回一個(gè)每個(gè)元素都是1
、形狀為size
、數(shù)據(jù)類型為dtype
的Tensor。文章來源地址http://www.zghlxwxcb.cn/news/detail-425599.html
實(shí)例
>>> torch.ones(2, 3)
tensor([[ 1., 1., 1.],
[ 1., 1., 1.]])
>>> torch.ones(5)
tensor([ 1., 1., 1., 1., 1.])
到了這里,關(guān)于深入淺出Pytorch函數(shù)——torch.ones的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!