IndexError: Dimension out of range (expected to be in range of [-2, 1], but got 3)
I created a random function with the line below
x = torch.randn(4, 3)

and used the transpose function as shown here
torch.transpose(x, 0, 1)

I got the error line below. Who can assist with a solution

IndexError                                Traceback (most recent call last)
&lt;ipython-input-19-28494ba2cedc&gt; in &lt;module&gt;()
----&gt; 1 torch.transpose(x, 0, 3)

IndexError: Dimension out of range (expected to be in range of [-2, 1], but got 3)


You are trying to transpose x = torch.randn(4, 3), which is 2D. torch.transpose(x, 0, 1) works fine because you swap dimensions 0 and 1. But then, you try to swap dimensions 0 and 3 by doing torch.transpose(x, 0, 3) but your x does not have the 3rd dimension
