Print() behaves differently when using formatted string

I have a pytorch tensor array named yTensor.
I was created from Pandas DF as so
yTensor = torch.tensor(dfY.values, dtype=torch.float32).to(device)

When I print an item such as
print(yTensor[0]), it prints “tensor(0., device=‘cuda:0’)”
But when I print it in formatted form
print(f’yTensor[0]={yTensor[0]}'), it prints “0.0”

Is that by design or some sort of bug?

It’s more or less by design and the different ways Python creates representatrions: printing a tensor directly uses the __str__ method under the hood while f"{tensor}" will use the __format__ method (if it exists). PyTorch implements both and the output is slightly different for scalar tensors.

Best regards

Thomas