# Convert python.list of 1d torch.Tensor to 2d torch.Tensor

**URL:** <https://discuss.pytorch.org/t/convert-python-list-of-1d-torch-tensor-to-2d-torch-tensor/164159>\
**Category:** Uncategorized\
**Created:** [October 22, 2022, 3:05pm UTC](https://discuss.pytorch.org/t/convert-python-list-of-1d-torch-tensor-to-2d-torch-tensor/164159 "2022-10-22T15:05:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kallinteris-Andreas](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/kallinteris-andreas/32/36794_2.png) [@Kallinteris-Andreas](https://discuss.pytorch.org/u/Kallinteris-Andreas)\
**Post date:** [October 22, 2022, 3:05pm UTC](https://discuss.pytorch.org/t/convert-python-list-of-1d-torch-tensor-to-2d-torch-tensor/164159/1 "2022-10-22T15:05:24Z")

</div>

```auto
(Pdb) p temp
[tensor([ 7.9873e-01, 9.9704e-01, -6.7735e-02, -3.6495e-02, 6.8676e-04,
         5.2778e-02, 6.9929e-03, 1.8170e-02, -4.0842e-02, 8.8229e-02,
        -7.0201e-02, 7.8539e-02, -1.6455e-02, 6.0354e-02, -2.1752e-01,
        -7.2633e-02, 1.0848e-01, 6.1456e-02, -6.3961e-02, -1.0666e-01,
        -2.4548e-02, -4.4079e-02, -6.6344e-03, 1.0026e-01, 1.4799e-01,
        -3.2869e-03, -7.5987e-02])]

```

For example, here `temp` is a python.list of a single 1d tensor of length 27, and I would like to convert it to a 2d tensor of dimensions (27,1)

if I had a python.list of 2 1d tensor of length 27, and I would like to convert it to a 2d tensor of dimensions (27,2)

if I had a python.list of N 1d tensor of length 27, and I would like to convert it to a 2d tensor of dimensions (27,N)

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![KFrank](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/k/ecb155/32.png) [@KFrank](https://discuss.pytorch.org/u/KFrank)\
**Post date:** [October 22, 2022, 9:00pm UTC](https://discuss.pytorch.org/t/convert-python-list-of-1d-torch-tensor-to-2d-torch-tensor/164159/2 "2022-10-22T21:00:10Z")

</div>

Hi Kallinteris!

> [@Kallinteris-Andreas](#):
>
> if I had a python.list of N 1d tensor of length 27, and I would like to convert it to a 2d tensor of dimensions (27,N)

Does [torch.stack()](https://pytorch.org/docs/1.12/generated/torch.stack.html) do what you want? Specifically, something like  
`torch.stack (list_of_tensors, dim = -1)`?

Best.

K. Frank
