pytorch math with exponents less than 1 return nan 's
torch.pow() returns nan when it's given the exponent argument between ranges -1 and 1

a = torch.randn(1,3)
a

&gt;&gt; tensor([[-1.7871, -0.5375, -0.1164]])

torch.pow(a, 2)      #or a**2

&gt;&gt; tensor([[3.1938, 0.2889, 0.0136]])

torch.pow(a,0.5)     #or a**0.5

&gt;&gt; tensor([[nan, nan, nan]])


expect result:

tensor([[-1.3368, -0.7331, -0.3412]])


Edit: turns out that ** works the same way as well. a**2 does the same thing with the tensor as torch.pow(a,2).  a**0.5 returns nan's like torch.pow does. 

The issue is that square root of a negative number is a non-real complex number. 

If you want to keep the sign and take the square root of its absolute value, the following code does the trick

torch.sign(a) * torch.pow(torch.abs(a), 0.5)

