# Alternate concatenation of tensors

**URL:** <https://discuss.pytorch.org/t/alternate-concatenation-of-tensors/165825>\
**Category:** Uncategorized\
**Created:** [November 13, 2022, 6:06am UTC](https://discuss.pytorch.org/t/alternate-concatenation-of-tensors/165825 "2022-11-13T06:06:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saswat](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/saswat/32/49862_2.png) [@Saswat](https://discuss.pytorch.org/u/Saswat)\
**Post date:** [November 13, 2022, 6:06am UTC](https://discuss.pytorch.org/t/alternate-concatenation-of-tensors/165825/1 "2022-11-13T06:06:13Z")

</div>

I have 2 tensors of shape [2, 1, 9] and [2, 1, 3]. I’d like to concatenate across the 3rd dimension alternatively (once every 4).

For example:

```auto
a = [[[1,2,3,4,5,6,7,8,9]],[[11,12,13,14,15,16,17,18,19]]]
b = [[[10, 20, 30]], [[1, 2, 3]]]
result = [[[1,2,3,10,4,5,6,20,7,8,9,30]],[[11,12,13,1,14,15,16,2,17,18,19,3]]]

```

How can I do this in pytorch?

---

<div class="post-metadata">

**Author:** ![Saswat](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/saswat/32/49862_2.png) [@Saswat](https://discuss.pytorch.org/u/Saswat)\
**Post date:** [November 13, 2022, 6:36am UTC](https://discuss.pytorch.org/t/alternate-concatenation-of-tensors/165825/2 "2022-11-13T06:36:20Z")

</div>

Solved by this

```auto
torch.concat([a.reshape((2, 1, 3, 3)), b.reshape(2, 1, 3, 1)], axis=-1).reshape((2, 1, -1))

```
