Print exact value of PyTorch tensor (floating point precision)(打印 PyTorch 张量的精确值(浮点精度))
本文介绍了打印 PyTorch 张量的精确值(浮点精度)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试打印 torch.FloatTensor 像:
I'm trying to print torch.FloatTensor like:
a = torch.FloatTensor(3,3)
print(a)
这样我可以得到一个值:
This way I can get a value like:
0.0000e+00 0.0000e+00 3.2286e-41
1.2412e-40 1.2313e+00 1.6751e-37
2.6801e-36 3.5873e-41 9.4463e+21
但我想获得更准确的值,例如小数点后 10 位:
But I want to get more accurate value, like 10 decimal point:
0.1234567891+01
使用其他 python 数值对象,我可以得到它:
With other python numerical objects, I could get it with:
print('{:.10f}'.format(a))
但在张量的情况下,我收到此错误:
but in the case of a tensor, I get this error:
TypeError: unsupported format string passed to torch.FloatTensor.__format__
如何打印更精确的张量值?
How can I print more precise values of tensors?
推荐答案
可以设置精度选项:
torch.set_printoptions(precision=10)
文档页面上有更多格式选项,它是与 numpy 非常相似.
There are more formatting options on the documentation page, it is very similar to numpy's.
这篇关于打印 PyTorch 张量的精确值(浮点精度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:打印 PyTorch 张量的精确值(浮点精度)
基础教程推荐
猜你喜欢
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 包装空间模型 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
