Pytorch學習日誌之函式用法記錄

2021-08-20 16:29:32 字數 414 閱讀 2633

1.torch.max() return 所有元素中的最大值.

torch.max(input,dim,keepdim=false),dim =0時返回每一列的最大值及索引,dim=1時返回每一行的最大值及索引。

keepdim=true時返回的值的形狀與dim相同

2.torch.squeeze(a)壓縮第a維維度為1的軸,torch.squeeze(),壓縮所有維度為1的軸,torch.unsqueeze(a),在第a個軸上擴充乙個維度為1的軸

3.torch.tensor.view(),根據原有資料重新分配為乙個新的張量,eg: x = torch.randn(2,4),y=x.view(4,2)

torch.tensor.view_as(tensor)相當於torch.tensor.view_as(tensor.size())

Pytorch之contiguous的用法

contiguous tensor變數呼叫contiguous 函式會使tensor變數在記憶體中的儲存變得連續。contiguous view只能用在contiguous的variable上。如果在view之前用了transpose,permute等,需要用contiguous 來返回乙個cont...

Pytorch之contiguous的用法

contiguous tensor變數呼叫contiguous 函式會使tensor變數在記憶體中的儲存變得連續。contiguous view只能用在contiguo的variable上。如果在view之前用了transpose,permute等,需要用contiguous 來返回乙個contig...

Python學習日誌之Python函式

python日誌之python函式 一 認識函式 1.什麼是函式 函式,function,通俗來說,函式,就是功能的意思,函式是用來封裝特定功能的,比如,在python中,len 是乙個函式,len 這個函式實現的功能可能是返回乙個字串的長度,所以說len 這個函式他的特定功能就是返回長度,再比如,...