Khabbab_Zakaria:

import torch
import numpy as np

mu1 = torch.Tensor([0.4651])
mu2 = torch.Tensor([0.4652])
sigma1 = torch.Tensor([0.7910])
sigma2 = torch.Tensor([0.7911])
output = torch.log(sigma2/sigma1) + (sigma1**2 + (mu1 - mu2)**2)/(2*sigma2**2) - torch.Tensor([0.5])

print(output)

mu1 = torch.Tensor([0.4651])
mu2 = torch.Tensor([0.4652])
sigma1 = torch.Tensor([0.7910])
sigma2 = torch.Tensor([0.7911])
output = np.log(sigma2.item()/sigma1.item()) + (sigma1.item()**2 + (mu1.item() - mu2.item())**2)/(2*sigma2.item()**2) - 0.5

print(output)



I believe that this is because numpy will do operations in float64 by default while in torch they are in float32. For example:
import torch
import numpy as np

mu1 = torch.Tensor([0.4651]).to(torch.double)
mu2 = torch.Tensor([0.4652]).to(torch.double)
sigma1 = torch.Tensor([0.7910]).to(torch.double)
sigma2 = torch.Tensor([0.7911]).to(torch.double)
output = torch.log(sigma2/sigma1) + (sigma1**2 + (mu1 - mu2)**2)/(2*sigma2**2) - torch.Tensor([0.5]).to(torch.double)

print(output)

mu1 = torch.Tensor([0.4651])
mu2 = torch.Tensor([0.4652])
sigma1 = torch.Tensor([0.7910])
sigma2 = torch.Tensor([0.7911])
output = np.log(sigma2.item()/sigma1.item()) + (sigma1.item()**2 + (mu1.item() - mu2.item())**2)/(2*sigma2.item()**2) - 0.5

print(output)
print(output.dtype)

yields the following output
tensor([2.3976e-08], dtype=torch.float64)
2.3976444829543198e-08
float64

on my machine.