The tensor pytorch type into common data types in python

Tensor variable y is assumed that a type of pytorch, as follows:

y = torch.sum(m)
print(y)
print(type(y))
print(y.item())
print(type(y.item()))

Using y.item () can be converted to float, the program output is as follows:

tensor(452.4124, device='cuda:0', grad_fn=<SumBackward0>)
<class 'torch.Tensor'>
452.4123840332031
<class 'float'>

Different versions of pytorch way to solve the problem may not like me this is pytorch1.2

Published 36 original articles · won praise 11 · views 6540

Guess you like

Origin blog.csdn.net/t20134297/article/details/103850377