# Swap axes in pytorch?

**URL:** <https://discuss.pytorch.org/t/swap-axes-in-pytorch/970>\
**Category:** Uncategorized\
**Created:** [March 9, 2017, 1:08pm UTC](https://discuss.pytorch.org/t/swap-axes-in-pytorch/970 "2017-03-09T13:08:30Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![fmassa](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/fmassa/32/58_2.png) [@fmassa](https://discuss.pytorch.org/u/fmassa)\
**Post date:** [March 9, 2017, 4:18pm UTC](https://discuss.pytorch.org/t/swap-axes-in-pytorch/970/7 "2017-03-09T16:18:54Z")

</div>

Indeed, it can be a shortcut to use

```python
tensor.transpose_(0, 1)

```

instead of

```python
tensor = tensor.transpose(0, 1)

```

But note that the difference in performance is not significant, as `transpose` does not copy memory nor allocate new memory, and only swaps the strides.

---

_[View the full topic](https://discuss.pytorch.org/t/swap-axes-in-pytorch/970)._
