creating tensor by composition of smaller tensors
I would like to create a 4x4 tensor that is composed of four smaller 2x2 tensors in this manner:
The tensor I would like to create:
in_t = torch.tensor([[14,  7,  6,  2],
                     [ 4,  8, 11,  1],
                     [ 3,  5,  9, 10],
                     [12, 15, 16, 13]])

I would like to create this tensor composed from these four smaller tensors:
a = torch.tensor([[14, 7], [ 4,  8]])
b = torch.tensor([[6,  2], [11,  1]])
c = torch.tensor([[3,  5], [12, 15]])
d = torch.tensor([[9, 10], [16, 13]])

I have tried to use torch.cat like this:
mm_ab = torch.cat((a,b,c,d), dim=0)

but I end up with an 8x2 tensor.

You can control the layout of your tensor and achieve the desired result with a combination of torch.transpose and torch.reshape. You can perform an outer transpose followed by an inner transpose:
&gt;&gt;&gt; stack = torch.stack((a,b,c,d))
tensor([[[14,  7],
         [ 4,  8]],

        [[ 6,  2],
         [11,  1]],

        [[ 3,  5],
         [12, 15]],

        [[ 9, 10],
         [16, 13]]])

Reshape-tranpose-reshape-transpose-reshape:
&gt;&gt;&gt; stack.reshape(4,2,-1).transpose(0,1).reshape(-1,2,4).transpose(0,1).reshape(-1,4)
tensor([[14,  7,  6,  2],
        [ 4,  8, 11,  1],
        [ 3,  5,  9, 10],
        [12, 15, 16, 13]])

Essentially, reshapes allow you to group and view your tensor differently while transpose operation will alter its layout (it won't remain contiguous) meaning you can achieve the desired output.
