# Transform CNN input dimension

**URL:** <https://discuss.pytorch.org/t/transform-cnn-input-dimension/102277>\
**Category:** Uncategorized\
**Created:** [November 10, 2020, 12:10pm UTC](https://discuss.pytorch.org/t/transform-cnn-input-dimension/102277 "2020-11-10T12:10:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snowe](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@snowe](https://discuss.pytorch.org/u/snowe)\
**Post date:** [November 10, 2020, 12:10pm UTC](https://discuss.pytorch.org/t/transform-cnn-input-dimension/102277/1 "2020-11-10T12:10:54Z")

</div>

Hi everyone 🙂

I have a question regarding possible transformations of a CNN input. I know that the input should be in the form `batch_size x number_of_channels x height x width`. Let’s assume I have a tensor of shape [2, 3, 5, 5]. So two images with three channels each and the image is of size 5 by 5.

Is there a neat way to transform this input into 3 x [2, 1, 5, 5]? Basically, I would like to split each channel of every image in the batch and then have 3 such inputs. All I can think of are a bunch of nested for loops but maybe there is a better / more common way to do this?

Any help is very much appreciated!

All the best  
snowe

---

<div class="post-metadata">

**Author:** ![klory](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/klory/32/5814_2.png) [@klory](https://discuss.pytorch.org/u/klory)\
**Post date:** [November 10, 2020, 3:23pm UTC](https://discuss.pytorch.org/t/transform-cnn-input-dimension/102277/2 "2020-11-10T15:23:34Z")

</div>

```auto
x = torch.randn(2,3,5,5)
x_ = x.transpose(0,1).unsqueeze(2)
x_ = list(x_)

```

---

<div class="post-metadata">

**Author:** ![snowe](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@snowe](https://discuss.pytorch.org/u/snowe)\
**Post date:** [November 11, 2020, 8:02am UTC](https://discuss.pytorch.org/t/transform-cnn-input-dimension/102277/3 "2020-11-11T08:02:53Z")

</div>

@klory Thank you so much, that is exactly what I was looking for! 🙂
