Hi,
I think this behavior is intentional as it makes more sense than anything to me, at least.
This is the prefered implementation in numpy too.
Personally, I think mean of empty tensor can be defined in this way: nothing/len(nothing) or clearer version [nan] / len([nan]) which only can produce two kind of output, 1. crash in runtime! 2. nan as the output
(I did not read the source code so I might be wrong about how it works exactly)
Also, if you look more intuitively, if we do not want to raise an exception, the best scenario is nan as there are many numerical operation that might produce nan as an unexpected bahvior.



 jaehyung.ca:

I think it would confuse people


Can you explain what is your idea and prefered bahvior? And why it would confuse people?

  
      stackoverflow.com
  
  
      
    
  

  mean, nanmean and warning: Mean of empty slice 7



  python, numpy, warnings



  asked by
  
  
    Michael Currie
  
  on 12:22AM - 17 Apr 15 UTC


  
  
    
    
  
  



  
      github.com/pytorch/xla
  
  
    
  
	  
  

  
    
      torch.mean with empty dim should nan 3
    

    
      
        opened 
        
          
        
        Aug 2, 2019
      
      

        
          closed 
        
          
        
        Sep 5, 2019
      
        

      
        
          
          ailzhang
        
      
    
  



  import torch
import torch_xla
device = 'xla:0'
# device='cpu'
shape = (2, 0, 4)
x = torch.randn(shape, device=device)
y = torch.mean(x)
print(y)
Expected behavior: cpu produce nan while xla...



    pytorch api


  
  
    
    
  
  


Bests