Why tensor.view() is not working in pytorch?
I have the following piece of code.

embedded = self.embedding(input).view(1, 1, -1)
embedded = self.drop(embedded)
print(embedded[0].size(), hidden[0].size())
concatenated_output = torch.cat((embedded[0], hidden[0]), 1)


The last line of the code is giving me the following error.


  RuntimeError: inconsistent tensor sizes at /data/users/soumith/miniconda2/conda-bld/pytorch-0.1.9_1487344852722/work/torch/lib/THC/generic/THCTensorMath.cu:141


Please note, when I am printing the tensor shapes at line no. 3, I am getting the following output. 

torch.size([1, 300]) torch.size([1, 1, 300]) 


Why I am getting [1, 300] shape for embedded tensor even though I have used the view method as view(1, 1, -1)?

Any help would be appreciated!

embedded was a 3d-tensor and hidden was a tuple of two elements (hidden states and cell states) where each element is a 3d-tensor. hidden was the output from LSTM layer. In PyTorch, LSTM returns hidden states [h] and cell states [c] as a tuple which made me confused about the error.

So, I updated the last line of the code as follows and it solved the problem.

concatenated_output = torch.cat((embedded, hidden[0]), 1)

