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 张量的精确值(浮点精度)


猜你喜欢
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01