Why doesn't mean work on bool tensors?

Why does the following work

x = torch.tensor([True, False, True])
x.sum().div(len(x))

and this one not ?

x = torch.tensor([True, False, True])
x.mean()

numpy.mean also works on boolean arrays.

It seems that numpy doesn’t work in the first code snippet:

x = torch.tensor([True, False, True])
x.numpy().sum().div(len(x))
> AttributeError: 'numpy.int64' object has no attribute 'div'

so the support seems to be swapped. :wink:

Feel free to create a feature request to support mean on BoolTensors and to discuss it with the code owners.

:face_with_open_eyes_and_hand_over_mouth: that’s bananas, didn’t expect that at all.
Who would have thought of this divergence :grinning:.

Cheers!

1 Like