01-02-張量簡介與創(chuàng)建

張量——是一個(gè)多維數(shù)組,它是標(biāo)量、向量、矩陣的高維拓展
張量創(chuàng)建

一、直接創(chuàng)建
data可以是list、numpy
notice:torch.from_numpy 共享內(nèi)存

二、依據(jù)數(shù)值創(chuàng)建
torch.zeros()
torch.zeros_like()
torch.ones()
torch.ones_like()
torch.full()
torch.full_like()
torch.arrange() 創(chuàng)建等差的一維張量

torch.linspace() 創(chuàng)建均分的一維張量
steps 數(shù)列長度,即張量元素的個(gè)數(shù)

torch.logspace() 創(chuàng)建對數(shù)均分的一維張量
base為對數(shù)的底

torch.eye() 創(chuàng)建單位對角矩陣(2維張量)

三、依概率分布創(chuàng)建張量
torch.nomal() 生成正態(tài)分布(高斯分布)
標(biāo)準(zhǔn)差:


torch.nomal()四種模式

torch.randn() 生成標(biāo)準(zhǔn)正態(tài)分布
torch.randn_like()

torch.rand() 在區(qū)間[0,1]上生成均勻分布
torch.rand_like()
torch.randint() 在區(qū)間[low,high]上,生成整數(shù)均勻分布
torch.randint_like()

torch.randperm()
torch.bernoulli()

標(biāo)簽: