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