A tensor in the shape [4, 3, 1] has 3 dimensions and contains 12 elements (4*3*1).
Print this random tensor in the same shape to see how the values are stored: print(torch.randn(4, 3, 1)).
Since your output has 8 values, you won’t be able to use a tensor with 12 elements to store them (unless you want to use default values for the other indices as described in the previous post).