Please let me know if this answer makes sense
landmarks_arr = []


for i in range(len(train_dataset)):
    landmarks = to_tensor(train_dataset[i]['landmarks'])
    landmarks[landmarks != landmarks] = 0  # this will set all nan to zero
    landmarks_arr.append(landmarks)
    
mean = torch.mean(torch.stack(landmarks_arr, dim=0))#, dim=(0, 2, 3))
std = torch.std(torch.stack(landmarks_arr, dim=0)) #, dim=(0, 2, 3))

max_val = 0.
tmp_max = 0.
for i in range(len(landmarks_arr)):
    tmp_max = torch.max(landmarks_arr[i])
    if max_val <= tmp_max:
        max_val = tmp_max
        
print('max val is: ', max_val)

print(mean.shape)
print("mean is {} and std is {}".format(mean/max_val, std/max_val))

Screenshot_2020-10-15_20-46-151782×1144 186 KB