# Repeat tensor only in the last dimension

**URL:** <https://discuss.pytorch.org/t/repeat-tensor-only-in-the-last-dimension/163332>\
**Category:** Uncategorized\
**Created:** [October 12, 2022, 6:03am UTC](https://discuss.pytorch.org/t/repeat-tensor-only-in-the-last-dimension/163332 "2022-10-12T06:03:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SungmanHong](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/sungmanhong/32/36192_2.png) [@SungmanHong](https://discuss.pytorch.org/u/SungmanHong)\
**Post date:** [October 12, 2022, 6:03am UTC](https://discuss.pytorch.org/t/repeat-tensor-only-in-the-last-dimension/163332/1 "2022-10-12T06:03:20Z")

</div>

I have a tensor of shape [2, 2] where the first 2 is the batch size

I want to make this tensor to [2, 64] at the forward function. (Repeat 32 times)  
How can I do it? the torch’s repeat api changes every dimension… (for e.g : [64, 64] comes out)

---

<div class="post-metadata">

**Author:** ![InnovArul](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/innovarul/32/5282_2.png) [@InnovArul](https://discuss.pytorch.org/u/InnovArul)\
**Post date:** [October 12, 2022, 6:15am UTC](https://discuss.pytorch.org/t/repeat-tensor-only-in-the-last-dimension/163332/2 "2022-10-12T06:15:53Z")

</div>

`torch.repeat()` lets us specify the number of times to repeat for each dimension.  
Something like below should work:

```auto
>>> import torch
>>> x = torch.randn(2,2)
>>> y = x.repeat(1, 32)
>>> y.shape
torch.Size([2, 64])

```
