網(wǎng)站首頁 編程語言 正文
pytorch和numpy默認(rèn)浮點(diǎn)類型位數(shù)
numpy中默認(rèn)浮點(diǎn)類型為64位,pytorch中默認(rèn)浮點(diǎn)類型位32位
測試代碼如下
- numpy版本:1.19.2
- pytorch版本:1.2.0
In [1]: import torch
In [2]: import numpy as np
# 版本信息
In [3]: "pytorch version: {}, numpy version: {}".format(torch.__version__, np.__version__)
Out[3]: 'pytorch version: 1.2.0, numpy version: 1.19.2'
# numpy
In [4]: dat_np = np.array([1,2,3], dtype="float")
In [5]: dat_np.dtype
Out[5]: dtype('float64')
# pytorch
In [6]: dat_torch = torch.tensor([1,2,3])
In [7]: dat_torch = dat_torch.float()
In [8]: dat_torch.dtype
Out[8]: torch.float32
pytorch和numpy的默認(rèn)類型與轉(zhuǎn)換問題
pytorch對于浮點(diǎn)類型默認(rèn)為float32,而numpy的默認(rèn)類型是float64,轉(zhuǎn)換的代碼:
torch.from_numpy(a).type(torch.FloatTensor)
torch.from_numpy(np.float32(a))
總結(jié)
原文鏈接:https://blog.csdn.net/u012633319/article/details/113784143
相關(guān)推薦
- 2022-06-19 Rainbond云原生部署SpringCloud應(yīng)用架構(gòu)實(shí)踐_云其它
- 2022-05-27 python中SQLAlchemy使用前端頁面實(shí)現(xiàn)插入數(shù)據(jù)_python
- 2022-06-13 Python數(shù)據(jù)類型及常用方法_python
- 2022-06-14 如何利用Python擬合函數(shù)曲線詳解_python
- 2022-08-22 Python連接數(shù)據(jù)庫使用matplotlib畫柱形圖_python
- 2022-05-10 fatal: Not a git repository (or any of the parent
- 2022-07-28 C++中strlen(),sizeof()與size()的區(qū)別_C 語言
- 2022-06-09 Python列表的索引與切片_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支