I think tensor.item() method have some errors

The current status is that we want to sum convolution layer feature maps based on index
to get the sum of the certain part of the feature maps.

I can’t understand the error situation that I posted on the image.
If the fake.item() got zero, Then we should get division by zero error not “float division by zero” error.
Is inferring tensor.item() on specific variable on various time is dangerous?

If (fake + real) is equal to zero, then why do you think the problem comes from the .item() method ?

Because when python divide value by zero, the name of the error is “division by zero” where as when divide float by zero, the output is “float divided by zero”
for example
“3/0” > “division by zero” error
“1.5/0” > “float division by zero” error
“0/0” > “division by zero” error

Hi @Yupjun
Try:

fake.dtype

if it returns torch.float32, fake.item() will return you a Python float scalar (.
And in Python:

>>> 0.0/0
ZeroDivisionError: float division by zero

so everything is expect here.