pytorch tensor of tensors to a tensor
When I print a torch tensor, I get the below output. How could I get that tensor without [] for the inner elements?
I printed the type of the first element and it returns &lt;class 'torch.Tensor'&gt; So this tensor seems to be a tensor of tensors...How could I convert it to a tensor of numbers?
tensor([[-5.6117e-01],
        [ 3.5726e-01],
        [-2.5853e-01],
        [-4.8641e-01],
        [-1.0581e-01],
        [-1.8322e-01],
        [-1.2732e+00],
        [-5.9760e-02],
        [ 1.2819e-01],
        [ 6.3894e-02],
        [-9.1817e-01],
        [-1.6539e-01],
        [-1.1471e+00],
        [ 1.9666e-01],
        [-6.3297e-01],
        [-4.0876e-01],
        [-2.4590e-02],
        [ 2.7065e-01],
        [ 3.5308e-01],
        [-4.6348e-01],
        [-4.1755e-01],
        [-1.1554e-01],
        [-4.2062e-01],
        [ 1.4067e-01],
        [-2.9788e-01],
        [-7.4582e-02],
        [-5.3751e-01],
        [ 1.1344e-01],
        [-2.6100e-01],
        [ 2.6951e-02],
        [-5.0437e-02],
        [-1.9163e-01],
        [-3.3893e-02],
        [-5.9640e-01],
        [-1.1574e-01],
        [ 1.4613e-01],
        [ 1.2263e-01],
        [-1.5566e-01],
        [ 1.4740e-01],
        [-9.9924e-01],
        [ 2.0878e-01],
        [-2.0074e-01],
        [ 7.8383e-02],
        [ 7.4679e-02],
        [-5.8065e-01],
        [ 6.7777e-01],
        [ 5.9879e-01],
        [ 6.6301e-01],
        [-4.7051e-01],
        [-2.5468e-01],
        [-2.7382e-01],
        [ 1.7585e-01],
        [ 3.6151e-01],
        [-9.2532e-01],
        [-1.6999e-01],
        [ 8.4971e-02],
        [-6.6083e-01],
        [-3.1204e-02],
        [ 6.3712e-01],
        [-5.8580e-02],
        [-7.7901e-04],
        [-4.6792e-01],
        [ 1.0796e-01],
        [ 7.8766e-01],
        [ 1.6809e-01],
        [-7.0058e-01],
        [-2.9299e-01],
        [-8.2735e-02],
        [ 2.0875e-01],
        [-2.9426e-01],
        [-7.6748e-02],
        [-1.5762e-01],
        [-5.7432e-01],
        [-5.2042e-01],
        [-1.5152e-01],
        [ 1.4119e+00],
        [-1.5752e-01],
        [-3.0565e-01],
        [-5.1378e-01],
        [-5.8924e-01],
        [-1.0163e+00],
        [-2.2021e-01],
        [ 2.9112e-02],
        [ 1.8521e-01],
        [ 6.2814e-01],
        [-6.8793e-01],
        [ 2.1395e-02],
        [ 5.7168e-01],
        [ 9.0977e-01],
        [ 3.8899e-01],
        [ 3.0209e-01],
        [ 2.4655e-01],
        [-1.1688e-01],
        [-5.9835e-02],
        [ 3.6426e-02],
        [-5.2782e-01],
        [ 1.4604e+00],
        [ 2.9685e-01],
        [-2.4077e-01],
        [ 1.0163e+00],
        [ 6.9770e-01],
        [-2.6183e-01],
        [ 3.6770e-01],
        [ 3.6535e-03],
        [ 4.2364e-01],
        [-5.4703e-01],
        [ 8.9173e-02],
        [-3.9032e-01],
        [-5.9740e-01],
        [ 3.7479e-02],
        [ 3.0257e-01],
        [ 8.2539e-02],
        [-6.0559e-01],
        [-4.3660e-01],
        [-7.0624e-01],
        [-5.0503e-01],
        [-4.0929e-01],
        [-2.3300e-01],
        [ 2.0298e-01],
        [-6.3697e-01],
        [-1.2584e-01],
        [ 5.6092e-02],
        [ 5.0150e-02],
        [-1.5358e-01],
        [ 2.9248e-02],
        [ 1.1180e-01],
        [-1.5535e-01],
        [ 1.1964e-01],
        [-6.5698e-01],
        [ 4.1923e-01],
        [ 7.4044e-02],
        [ 2.4536e-02],
        [ 3.2647e-01],
        [-7.7464e-01],
        [ 3.9898e-01],
        [-2.5777e-01],
        [ 8.5569e-02],
        [-4.0305e-01],
        [ 5.4463e-01],
        [-3.4124e-01],
        [-4.0789e-01],
        [ 4.2093e-01],
        [-3.8487e-01],
        [-4.0491e-01],
        [-2.1539e-01],
        [-1.7979e-02],
        [ 3.2492e-01],
        [-2.0894e-01],
        [ 2.5629e-01],
        [ 9.6046e-01]], device='cuda:0', grad_fn=&lt;AddmmBackward0&gt;)


That tensor has a singleton dimension (ie. it's of shape [Nx1]). Just squeeze that dimension or pick the 0th element:
In [1]: import torch

In [2]: a = torch.zeros([10,1])

In [3]: a
Out[3]: 
tensor([[0.],
        [0.],
        [0.],
        [0.],
        [0.],
        [0.],
        [0.],
        [0.],
        [0.],
        [0.]])

In [4]: a[:,0]
Out[4]: tensor([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])

In [5]: a.squeeze(1)
Out[5]: tensor([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])

