torch.linspace(1, 16, 16).view(4, 4)
mask = torch.gt(a, 8)
a = torch.tensor([[0, 1, 2, 0], [2, 3, 0, 1]])
1 Tensor的裁剪運算對Tensor中的元素進(jìn)行范圍過濾常用于梯度裁剪(gradient clipping)颅筋,即在發(fā)生梯度離散或者梯度爆炸時對梯度的處理torch.clamp(input, min, max, out=None) → Tensor:將輸入input張量每個元素的夾緊到區(qū)間 [min,max],并返回結(jié)果到一個新張量输枯。
2 Tensor的索引與數(shù)據(jù)篩選
torch.where(codition,x,y):按照條件從x和y中選出滿足條件的元素組成新的tensor议泵,輸入?yún)?shù)condition:條件限制,如果滿足條件桃熄,則選擇x先口,否則選擇y作為輸出。
torch.gather(input,dim,index,out=None):在指定維度上按照索引賦值輸出瞳收,沒看懂
tensortorch.inex_select(input,dim,index,out=None):按照指定索引賦值輸出
tensortorch.masked_select(input,mask,out=None):按照mask輸出tensor碉京,輸出為向量torch.take(input,indices):將輸入看成1D-tensor,按照索引得到輸出tensortorch.nonzero(input,out=None):輸出非0元素的坐標(biāo)
3 Tensor的組合/拼接
torch.cat(seq,dim=0,out=None):按照已經(jīng)存在的維度進(jìn)行拼接torch.stack(seq,dim=0,out=None):沿著一個新維度對輸入張量序列進(jìn)行連接螟深。序列中所有的張量都應(yīng)該為相同形狀收夸。
Whisper語音轉(zhuǎn)文字