Pytorch's stack() adds dimension?
I am looking to stack one shape=(1,2) tensor array on top of another shape=(1,2) array, across dim=1, using pytorch's stack() method.

&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; import torch
&gt;&gt;&gt; np_a = np.array([[1,2]])
&gt;&gt;&gt; np_b = np.array([[3,4]])
&gt;&gt;&gt; print(np_a)
[[1 2]]
&gt;&gt;&gt; print(np_b)
[[3 4]]
&gt;&gt;&gt; t_a = torch.from_numpy(np_a)
&gt;&gt;&gt; t_b = torch.from_numpy(np_b)
&gt;&gt;&gt; print(t_a)
tensor([[1, 2]])
&gt;&gt;&gt; print(t_b)
tensor([[3, 4]])
&gt;&gt;&gt; t_stacked = torch.stack((t_a, t_b), dim=1)
&gt;&gt;&gt; print(t_stacked)
tensor([[[1, 2],
         [3, 4]]])


The resulting tensor has an added dimension and now has a shape=(1,2,2).  Why doesn't pytorch's stack() behave like numpy's vstack()?  See below:

&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; np_a = np.array([[1,2]])
&gt;&gt;&gt; np_b = np.array([[3,4]])
&gt;&gt;&gt; stacked = np.vstack((np_a, np_b))
&gt;&gt;&gt; print(stacked)
[[1 2]
 [3 4]]


How do I make pytorch not add a dimension?

I can't tell you why it was decided to have pytorch's stack behave differently from numpy (maybe compatibility with luatorch?). Anyway, to get the desired outcome you can use torch.cat:

&gt;&gt;&gt; torch.cat((t_a, t_b), dim=0)     
tensor([[1, 2],
        [3, 4]])

