# Why is \`transpose\` recursive?

**URL:** https://discourse.julialang.org/t/why-is-transpose-recursive/2550
**Category:** Internals & Design
**Created:** [March 8, 2017, 10:43pm UTC](https://discourse.julialang.org/t/why-is-transpose-recursive/2550 "2017-03-08T22:43:33Z")
**Posts on this page:** 4
**Page:** 2

<div class="post-metadata">

### Author: ![JoshLangsfeld](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshlangsfeld/32/8211_2.png) [@JoshLangsfeld](https://discourse.julialang.org/u/JoshLangsfeld)
#### Post date: [March 10, 2017, 2:27am UTC](https://discourse.julialang.org/t/why-is-transpose-recursive/2550/21 "2017-03-10T02:27:31Z")

</div>

At least `reshape(vec,(1,:))` is possible now, which helps.

Since the issue is entirely that people want something that comes close to the conciseness of `'`, would it make sense to have a convenience function that exclusively swaps the first two dimensions? `flip(vec)`?

---

<div class="post-metadata">

### Author: ![andyferris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andyferris/32/235_2.png) [@andyferris](https://discourse.julialang.org/u/andyferris)
#### Post date: [March 10, 2017, 4:24am UTC](https://discourse.julialang.org/t/why-is-transpose-recursive/2550/22 "2017-03-10T04:24:24Z")

</div>

Like I said, I feel one problem with `'` was that it was a reversible toggle. You can’t tell the shape of the output without knowing the shape of the input. If you get too many of these, and you’re reading code you’re not intimately familiar with, it is hard to grasp what is going on. `flip` would be the same.

But now in Julia we have vectors, row vectors, column matrices and row matrices, and there is probably a situation where you might want to “cast” something to any of those shapes…

---

<div class="post-metadata">

### Author: ![juthohaegeman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juthohaegeman/32/8620_2.png) [@juthohaegeman](https://discourse.julialang.org/u/juthohaegeman)
#### Post date: [March 10, 2017, 8:25am UTC](https://discourse.julialang.org/t/why-is-transpose-recursive/2550/23 "2017-03-10T08:25:07Z")

</div>

I agree with @StefanKarpinski here. There are many custom types that you can create, which behave like a ring or field, but which you do not necessarily want to make a subtype of `Number`. So it makes sense to build matrices with this element type, without having to define `transpose` as an identity operation this type in itself. I don’t think there is any mathematical motivation for making transpose act recursively. Block matrices are the only exception, but that’s only after the programmer made a ambiguous mathematical interpretation for a data structure which could also represent other mathematical structures. As such, a specific type for block matrices would indeed serve this purpose better.

---

<div class="post-metadata">

### Author: ![andyferris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andyferris/32/235_2.png) [@andyferris](https://discourse.julialang.org/u/andyferris)
#### Post date: [March 15, 2017, 1:27pm UTC](https://discourse.julialang.org/t/why-is-transpose-recursive/2550/24 "2017-03-15T13:27:35Z")

</div>

For those interested in this subject, it might be worth noting “Taking matrix transposes seriously” at [https://github.com/JuliaLang/julia/issues/20978](https://github.com/JuliaLang/julia/issues/20978).

[Previous page](https://discourse.julialang.org/t/why-is-transpose-recursive/2550.md?page=1)
