Why IntTensor * 1.0 is still a IntTensor?

import torch
a = torch.Tensor([1, 3])
b = torch.Tensor([1, 4])
torch.sum(a == b) * 1.0 / 3 # ==> 0

We’re working on making binary op semantics match Python / numpy semantics. This will be in a future release, thank you for pointing it out, @fangyh

1 Like

for now, you should be able to do torch.sum(a == b).float()

1 Like