pytorch常用數(shù)據(jù)類型所占字節(jié)數(shù)對(duì)照表一覽
PyTorch上的常用數(shù)據(jù)類型如下
Data type | dtype | CPU tensor | GPU tensor | Size/bytes |
---|---|---|---|---|
32-bit floating | torch.float32 or torch.float | torch.FloatTensor | torch.cuda.FloatTensor | 4 |
64-bit floating | torch.float64 or torch.double | torch.DoubleTensor | torch.cuda.DoubleTensor | 8 |
16-bit floating | torch.float16or torch.half | torch.HalfTensor | torch.cuda.HalfTensor | - |
8-bit integer (unsigned) | torch.uint8 | torch.ByteTensor | torch.cuda.ByteTensor | 1 |
8-bit integer (signed) | torch.int8 | torch.CharTensor | torch.cuda.CharTensor | - |
16-bit integer (signed) | torch.int16or torch.short | torch.ShortTensor | torch.cuda.ShortTensor | 2 |
32-bit integer (signed) | torch.int32 or torch.int | torch.IntTensor | torch.cuda.IntTensor | 4 |
64-bit integer (signed) | torch.int64 or torch.long | torch.LongTensor | torch.cuda.LongTensor | 8 |
以上PyTorch中的數(shù)據(jù)類型和numpy中的相對(duì)應(yīng),占用字節(jié)大小也是一樣的
補(bǔ)充:pytorch tensor比較大小 數(shù)據(jù)類型要注意
如下
a = torch.tensor([[0, 0], [0, 0]]) print(a>=0.5)
輸出
tensor([[1, 1],
[1, 1]], dtype=torch.uint8)
結(jié)果明顯不對(duì), 分析原因是因?yàn)? a是long類型, 而0.5是float. 0.5會(huì)被轉(zhuǎn)化為 long, 變?yōu)?. 因此結(jié)果會(huì)出錯(cuò), 做出如下修改就可以得到正確答案
正確用法:
a = torch.tensor([[0, 0], [0, 0]]).float() print(a>=0.5)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
python用fsolve、leastsq對(duì)非線性方程組求解
這篇文章主要為大家詳細(xì)介紹了python用fsolve、leastsq對(duì)非線性方程組進(jìn)行求解,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12linux之父進(jìn)程使用kill函數(shù)殺死子進(jìn)程方式
這篇文章主要介紹了linux之父進(jìn)程使用kill函數(shù)殺死子進(jìn)程方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06python實(shí)現(xiàn)ModBusTCP協(xié)議的client功能
Modbus TCP 是一種基于 TCP/IP 協(xié)議棧的 Modbus 通信協(xié)議,它用于在工業(yè)自動(dòng)化系統(tǒng)中進(jìn)行設(shè)備之間的通信,只要通過(guò)pymodbus或pyModbusTCP任意模塊就可以實(shí)現(xiàn),本文采用pymodbus,感興趣的朋友跟隨小編一起看看吧2023-10-10手把手教你快速安裝gpu版本的pytorch(詳細(xì)圖文教程)
在Windows?10上安裝PyTorch時(shí),通常默認(rèn)安裝的是CPU版本,且下載速度較慢,本文提供了一個(gè)詳細(xì)的安裝指南,包括如何檢查CUDA版本、選擇合適的PyTorch、torchvision和torchaudio版本,并通過(guò)pip而非conda進(jìn)行安裝,文中通過(guò)圖文介紹的非常詳細(xì),需要的朋友可以參考下2024-09-09pandas計(jì)算相關(guān)系數(shù)corr返回空的問(wèn)題解決
本文主要介紹了pandas計(jì)算相關(guān)系數(shù)corr返回空的問(wèn)題解決,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-01-01