print exact value of tensor(floating point precision) with pytorch

前端 未结 2 2008
后悔当初
后悔当初 2021-01-04 22:10

I\'m trying to print torch.FloatTensor like

a = torch.FloatTensor(5,5)
print(a)

this way I can got a value like

0.0000e+00          


        
相关标签:
2条回答
  • 2021-01-04 22:24

    You can set the precision options

    torch.set_printoptions(precision=10)
    

    There are more formatting options on the documentation page: http://pytorch.org/docs/master/torch.html#creation-ops it is very similar to numpys.

    0 讨论(0)
  • 2021-01-04 22:26

    Just as a side note, this functionality has been taken from numpy. One of the reasons why PyTorch is smart is because they took many the good ideas from numpy.

    However, in numpy the default precision is 8 and in PyTorch the default is 4.

    0 讨论(0)
提交回复
热议问题