[英]How can I set precision when printing a PyTorch tensor with integers?
I have:我有:
mask = mask_model(input_spectrogram)
mask = torch.round(mask).float()
torch.set_printoptions(precision=4)
print(mask.size(), input_spectrogram.size(), masked_input.size())
print(mask[0][-40:], mask[0].size())
This prints:这打印:
tensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0.], grad_fn=<SliceBackward>) torch.Size([400])
But I want it to print 1.0000
instead of 1.
.但我希望它打印
1.0000
而不是1.
. Why won't my set_precision
do it?为什么我的
set_precision
不这样做? Even when I converted to float()
?即使我转换为
float()
?
Unfortunately, this is simply how PyTorch displays tensor values.不幸的是,这只是 PyTorch 显示张量值的方式。 Your code works fine, if you do
print(mask * 1.1)
, you can see that PyTorch does indeed print out 4 decimal values when the tensor values can no longer be represented as integers.您的代码运行良好,如果您执行
print(mask * 1.1)
,您可以看到当张量值不能再表示为整数时,PyTorch 确实会打印出 4 个十进制值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.