pytorch中的linspace函式

2022-08-15 02:33:15 字數 482 閱讀 8601

在pytorch中,我們經常會生成一系列的資料,例如我要生成從2,3,4,5,6,7,8,9,10,11十個數字,自己寫出來有點傻,所以自動生成是乙個好辦法。

直接看**,非常簡單:

import torch

torch.linspace(2,11,10,dtype=type(1.0))

'''===output===

tensor([ 2., 3., 4., 5., 6., 7., 8., 9., 10., 11.], dtype=torch.float64)

'''

這裡linspace函式裡面引數代表(start, stop, num, dtype),即(開始的數,結束的數,總共要多少個數,數的型別)。我這裡用了type(1.0),所以最後就生成了是float型別。你也可以把他們換成type(1),就生成整型啦。

Pytorch 中 torchvision的錯誤

在學習pytorch的時候,使用 torchvision的時候發生了乙個小小的問題 安裝都成功了,並且import torch也沒問題,但是在import torchvision的時候,出現了如下所示的錯誤資訊 dll load failed 找不到指定模組。首先,我們得知道torchvision在...

pytorch中的乘法

總結 按元素相乘用torch.mul,二維矩陣乘法用torch.mm,batch二維矩陣用torch.bmm,batch 廣播用torch.matmul if name main a torch.tensor 1 2,3 b torch.arange 0,12 reshape 4 3 c torch...

pytorch中index select 的用法

a torch.linspace 1,12,steps 12 view 3,4 print a b torch.index select a,0,torch.tensor 0,2 print b print a.index select 0,torch.tensor 0,2 c torch.inde...