The behavior of calling mean on an uninitialized tensor is undefined. I believe pytorch is interpreting the data as if it were valid numbers, which is why you get a result. However, there’s no guarantees for the data that is going to be in the tensor, so that’s why you get such unpredictable results. One possible explanation for why you get nan is one of the entries is interpreted by pytorch as nan, and the mean of a tensor with a nan element is always nan.