Pytorch自學(xué)筆記

1.1? 創(chuàng)建矩陣

torch.tensor(data)

torch.Tensor(dim1,dim2) #也可以是IntTensor或者FloatTensor,也可以跟torch.tensor混用

torch.as_tensor(data,dtype=,device=)

torch.from_numpy(ndarray)

torch.empty(size)

torch.empty_like(input)

1.2 特殊矩陣

torch.zeros(size)

torch.zeros_like(input, dtype)

torch.ones(size)

torch.ones_like(input, dtype)

torch.eye(size)

1.3 序列

torch.arange(start, end, step) ?# 不包括end, step是兩個(gè)點(diǎn)間距

torch.range(start, end, step) # 包括end,step是兩個(gè)點(diǎn)間距

torch.linspace(start, end, steps) # 包括end, steps 是點(diǎn)的個(gè)數(shù),包括端點(diǎn), (等距離)

torch.logspace(start, end, steps) # 10的幾次冪

1.4 稀疏矩陣

torch.sparse_coo_tensor(indices, values, size) # indices 值的x-y坐標(biāo),size 稀疏矩陣的大小

1.5相同值填充矩陣

torch.full(size, fill_value)

torch.full_like(input, fill_value)

1.6 隨機(jī)矩陣生成

torch.rand(size) # 數(shù)值范圍[0, 1), size = [2,3] or 2,3

torch.rand_like(input, dtype) # 形狀和input相同

torch.randn(size) ?# 標(biāo)準(zhǔn)正態(tài)分布 N(0,1)

torch.randn_like(input, dtype)

torch.randint(low = 0, high, size) # 整數(shù)范圍[low, high), ?e.g. torch.randint(3, 8, [2,3])

torch.normal(mean=torch.full([10],0),std=torch.arange(1,0,-0.1))#相當(dāng)于整個(gè)拉長(zhǎng)了

1.7 隨機(jī)排列生成

torch.randperm(n) # 生成一個(gè)0到n-1的n-1個(gè)整數(shù)的隨機(jī)排列

1.8 矩陣切片與索引

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容