Undoing tensor dstack and restack column-wise
I have two, tensors, a and b:
import torch

a = torch.tensor(([1,2],
                  [3,4],
                  [5,6],
                  [7,8]))

b = torch.tensor(([0,0],
                  [1,1],
                  [2,2],
                  [3,3]))

Which I can stack both horizontally or depth-wise.
d = torch.dstack([a, b])
h = torch.hstack([a, b])

Now, is there any PyTorch function, preferably in one line, that I can apply to d to get h? It sounds like I want to undo the depth-wise stacking, and re-stack them column-wise. I've tried reshaping, and flattening, but neither work, as they both disrupt the ordering of the values.

in your case use torch.unbind
import torch

a = torch.tensor(([1,2],
                  [3,4],
                  [5,6],
                  [7,8]))

b = torch.tensor(([0,0],
                  [1,1],
                  [2,2],
                  [3,3]))

d = torch.dstack([a, b])
h = torch.hstack(torch.unbind(d,2)) # get h from d

