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 张量的精确值(浮点精度)
基础教程推荐
猜你喜欢
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
