github.com/pytorch/pytorch
  
  
    
  
	  
  

  
    
      After replace `torch.Tensor.__getitem__` with some other implementation, indexing with tensors of one dim behaves unexpectedly. 2
    

    
      
        opened 
        
          
        
        Jul 22, 2020
      
      

        
          closed 
        
          
        
        Jul 28, 2020
      
        

      
        
          
          ChieloNewctle
        
      
    
  



  🐛 Bug
To Reproduce
Steps to reproduce the behavior:
import torch
a = torch.tensor([[1, 2, 3], [4, 5, 6]])
b = torch.tensor([True, True])
print(a[b].shape)
print('__getitem__' in torch.Tensor.__dict__)
f =...



    triaged


  
  
    
    
  
  


In the above issue raised in the github repository of pytorch, the person who opened the issue has replaced torch.Tensor.__getitem__ with their own lambda.
I made the same change as follows:
f = torch.Tensor.__getitem__
g = lambda *a, **kw: f(*a, **kw)
torch.Tensor.__getitem__ = g

And now I tried indexing x with index_t, and got the following output: