pytorch和numpy默认浮点类型位数详解
作者:gy笨瓜 时间:2021-11-10 10:19:49
pytorch和numpy默认浮点类型位数
numpy中默认浮点类型为64位,pytorch中默认浮点类型位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的默认类型与转换问题
pytorch对于浮点类型默认为float32,而numpy的默认类型是float64,转换的代码:
torch.from_numpy(a).type(torch.FloatTensor)
torch.from_numpy(np.float32(a))
来源:https://blog.csdn.net/u012633319/article/details/113784143
标签:pytorch,numpy,默认浮点类型,位数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
网站细节论(1)--阅读的细节
2007-12-21 12:16:00
![](https://img.aspxhome.com/file/UploadPic/200712/21/20071221122819275s.gif)
python+OpenCV实现图像拼接
2023-01-28 08:09:26
![](https://img.aspxhome.com/file/2023/2/113112_0s.jpg)
python直接获取API传递回来的参数方法
2023-11-10 18:01:59
PL/SQL 类型格式转换
2009-02-26 11:07:00
SQL Server数据库对于应用程序的关系
2010-09-08 09:42:00
Python Tkinter Menu组件详解
2021-07-24 06:51:18
![](https://img.aspxhome.com/file/2023/3/81863_0s.png)
Python 调用API发送邮件
2021-08-26 04:20:22
![](https://img.aspxhome.com/file/2023/7/107017_0s.png)
怎样正确的解决 MySQL 中文模糊检索问题
2008-12-19 17:26:00
Python字符串对齐、删除字符串不需要的内容以及格式化打印字符
2021-09-17 10:46:33
交互设计师的尴尬-我的强项是什么?
2008-12-29 14:00:00
在VScode中引用自定义模块问题
2023-08-13 03:50:37
![](https://img.aspxhome.com/file/2023/3/111943_0s.png)
Python中的if、else、elif语句用法简明讲解
2023-05-18 22:18:59
Python如何实现定时器功能
2023-04-13 23:19:28
使用Python实现从各个子文件夹中复制指定文件的方法
2023-11-09 12:04:05
python实现文件助手中查看微信撤回消息
2023-09-03 07:23:50
asp如何在数据库中用好Transaction?
2010-06-22 21:07:00
Python数学建模PuLP库线性规划进阶基于字典详解
2022-03-11 18:04:04
PyQt5创建一个新窗口的实例
2021-12-31 02:49:44
![](https://img.aspxhome.com/file/2023/6/93516_0s.jpg)
CSS 设计中的黄金分割率应用
2008-11-12 12:17:00
![](https://img.aspxhome.com/file/UploadPic/200811/12/u2008111121121-91s.png)
Python socket实现简单聊天室
2022-06-20 02:13:27