I have a simple code that generates a random tensor (float32). Then I compare each of the values in the tensor equal to the first number in the tensor. I got weird result where all True values are returning.
import torch
torch.manual_seed(1)
a = torch.rand(2, 10)
tensor([[0.7576, 0.2793, 0.4031, 0.7347, 0.0293, 0.7999, 0.3971, 0.7544, 0.5695,
0.4388], [0.6387, 0.5247, 0.6826, 0.3051, 0.4635, 0.4550, 0.5725, 0.4980, 0.9371,
0.6556]])a != 0.7576
tensor([[True, True, True, True, True, True, True, True, True, True], [True, True, True, True, True, True, True, True, True, True]])
Meanwhile If I changed to something like this, I got the right returning boolean values.
a != a[0][0]
tensor([[False, True, True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True, True, True]])
I am curious why this happens? Thanks!