# Std of single element tensor is nan

The std computed on a tensor containing single element is `nan`.
Precisely:
`

v = th.randn(1, 128, 4, 4)
v.std(dim=0)
tensor([[[nan., nan., nan., nan.],
[nan., nan., nan., nan.],
[nan., nan., nan., nan.],
[nan., nan., nan., nan.]],

``````    [[nan., nan., nan., nan.],
[nan., nan., nan., nan.],
[nan., nan., nan., nan.],
[nan., nan., nan., nan.]],

[[nan., nan., nan., nan.],
[nan., nan., nan., nan.],
[nan., nan., nan., nan.],
[nan., nan., nan., nan.]],

...,

[[nan., nan., nan., nan.],
[nan., nan., nan., nan.],
[nan., nan., nan., nan.],
[nan., nan., nan., nan.]],

[[nan., nan., nan., nan.],
[nan., nan., nan., nan.],
[nan., nan., nan., nan.],
[nan., nan., nan., nan.]],

[[nan., nan., nan., nan.],
[nan., nan., nan., nan.],
[nan., nan., nan., nan.],
[nan., nan., nan., nan.]]])
``````

`

In fact, just one element is:
`

v = th.randn(1)
v.std()
tensor(nan.)
`

Theoretically speaking, shouldn’t the `std` of a single element be 0? Please help me to clear this confusion

Have you checked the documentation for std?
PyTorch uses the unbiased estimate of std by default and that is not well-defined for a single element. If you set unbiased=False, you’ll get what I would suppose is what you expect.

Best regards

Thomas

Hi Thomas,

Thank you for the response. Oh yes, bessel’s correction uses (n - 1) instead of (n) for calculating the std. This would cause a ‘divide by 0’ case resulting in `nan`. I actually got caught up in searching for the source of this function. Thanks again.

Best regards,
Animesh