I have a 3D tensor (5x9x12) I want to cast it to a (5x9x1) tensor through the linear layer. But I found that the nn.LinearLayer require that the input should be a matrix instead of a 3d tensor. How can I achieve my task?
You can do that with Tensor.view()
x = x.view(-1, 12) b_size = x.size(0) x = linear(x) x = x.view(b_size, -1, 1)
Thanks, it is likely to solve my problem. If there is a single function to to the trick, it would be more clear.
Based on Linear layer documentation, you simply need to pass the 3d input through a linear(12,1) layer.
Could you explain how to do this in a non iterative manner? I think it would be very helpful