Say if I got two tensors like [[1,1],[1,1]] and [[2,2],[2,2]], how could I interleave them along n_w or n_h dimension to get [[1,2,1,2],[1,2,1,2]] or [[1,1],[2,2],[1,1],[2,2]]? In TensorFlow I could achieve such goal using tf.reshape after tf.stack, but transferring to PyTorch using view after torch.stack does not return what I want.
I just started using pytorch on version 0.4 so maybe it’s something they added recently. Also, I’m sure there’s a good reason you’ve made calls to contiguous(), is there something I should know about the view?
from einops import rearrange
rearrange([a, b], 't h w -> h (w t)') # [[1,2,1,2],[1,2,1,2]]
rearrange([a, b], 't h w -> (h t) w') # [[1,1],[2,2],[1,1],[2,2]]